Cannot reduce size of RCP view when migrated to Eclipse 4 - eclipse

I'm currently working on migrating a set of eclipse RCP applications from 3.6 to 4.2.
I'm struggling with an issue with RCP perspectives that view height cannot be reduced below a certain size (looks like 10% from the window height).
The code works fine in eclipse 3.x and user can reduce the view height by dragging the border.
However, in 4.x the height of top most view (button view) can only be reduced upto a certain value.
Can anybody help with this, please?
public class Perspective implements IPerspectiveFactory {
public static final String ID = "im.rcpTest2.fixedperspective";
public void createInitialLayout(IPageLayout layout) {
String editorArea = layout.getEditorArea();
layout.setEditorAreaVisible(false);
layout.addStandaloneView(ButtonView.ID, false, IPageLayout.TOP,
0.1f, editorArea);
layout.addStandaloneView(View.ID, false, IPageLayout.LEFT,
0.25f, editorArea);
IFolderLayout folder = layout.createFolder("messages", IPageLayout.TOP,
0.5f, editorArea);
folder.addPlaceholder(View2.ID + ":*");
folder.addView(View2.ID+":2");
folder.addView(View2.ID+":3");
layout.getViewLayout(ButtonView.ID).setCloseable(false);
layout.getViewLayout(View.ID).setCloseable(false);
}
}
public class ButtonView extends ViewPart {
public ButtonView() {
}
public static final String ID = "im.rcptest2.ButtonView"; //$NON-NLS-1$
private Text text;
/**
* Create contents of the view part.
* #param parent
*/
#Override
public void createPartControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setBackground(SWTResourceManager.getColor(SWT.COLOR_GRAY));
container.setLayout(new GridLayout(2, false));
text = new Text(container, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
{
Button btnMybutton = new Button(container, SWT.NONE);
btnMybutton.setText("MyButton");
}
}
#Override
public void setFocus() {
// TODO Auto-generated method stub
}
}

This looks like the value
int minSashPercent = 10;
in org.eclipse.e4.ui.workbench.renderers.swt.SashLayout
There does not seem to be a way to change this value. So the only thing you could do would be to write a custom Sash Renderer class by providing your own Renderer Factory.

Related

Eclipse JFace/SWT ViewerFilter select never gets called

I'm trying to build a simple dialog with a TableViewer in it, along with a checkbox which would filter the data. However the table is empty and the filtering never gets done. Whats wrong with this code?
public class AsTestDialog extends TitleAreaDialog {
private Table table;
private AsTestFilter filter;
private TableViewer tableViewer;
public AsTestDialog(Shell parentShell) {
super(parentShell);
}
#Override
public void create() {
super.create();
setTitle("Table Test");
}
#Override
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
area.setLayout(new GridLayout(1, false));
tableViewer = new TableViewer(area, SWT.BORDER | SWT.FULL_SELECTION);
table = tableViewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tblclmnNewColumn = tableViewerColumn.getColumn();
tblclmnNewColumn.setWidth(130);
tblclmnNewColumn.setText("Column1");
TableViewerColumn tableViewerColumn_2 = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tblclmnId = tableViewerColumn_2.getColumn();
tblclmnId.setWidth(150);
tblclmnId.setText("Column2");
Composite composite = new Composite(area, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
Button btnFilter = new Button(composite, SWT.CHECK);
btnFilter.setBounds(10, 10, 111, 20);
btnFilter.setText("Filter");
btnFilter.addSelectionListener(new SelectionListener() {
#Override
public void widgetSelected(SelectionEvent e) {
System.out.println("CHECKBOX SELECTED");
filter.setFilterType("foobar");
tableViewer.refresh();
}
#Override
public void widgetDefaultSelected(SelectionEvent e) {}
});
addTestData(table);
//Filter
filter = new AsTestFilter();
tableViewer.addFilter(filter);
tableViewer.getTable().pack();
tableViewer.refresh();
return area;
}
private void addTestData(Table table) {
TableItem item1 = new TableItem(table, SWT.NONE);
item1.setText(new String[] {"1","2"});
item1.setData("1");
TableItem item2 = new TableItem(table, SWT.NONE);
item2.setText(new String[] {"3","4"});
item2.setData("3");
}
}
The filter class:
public class AsTestFilter extends ViewerFilter {
private String filterType = "all";
public void setFilterType(String tp) {
this.filterType = tp;
}
#Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
System.out.println("SELECT CALLED: "+filterType);
return true;
}
}
If you are using the JFace TableViewer you must use a 'content provider' set with
tableViewer.setContentProvider(provider);
and then call
tableViewer.setInput(input data);
creating TableItem objects directly will not work properly as TableViewer expects to create these objects itself.
If you have a simple array or List of objects the content provider can simply be:
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
and the set input:
tableViewer.setInput(array or list);
Your filter is not called because you have not called setInput, the table viewer does nothing until this is called.
The ViewerFilter operates on the TableViewer's input, which will be null in your case as you aren't using tableViewer.setInput(model). Instead you are creating TableItems directly.
You will need to set up a content provider, label provider, and define a model which you can pass to .setInput for the table viewer, and remove the function which directly creates the TableItems.
Once you do this, the ViewerFilter should work.
There are plenty of tutorials around which describe this, including https://eclipse.org/articles/Article-Table-viewer/table_viewer.html and http://wiki.eclipse.org/index.php/JFaceSnippets

How to create a toolbar inside viewpart (Not use plugin.xml)

I Created a ToolItem "Save As" like image above, But it not display at toolbar position. So how to create a toolbar inside viewpart (Not use plugin.xml)
IMAGE EXAMPLE
This is my code Create Toolbar:
public void createToolbar(Composite parent) {
// Create composite Toolbar and set layout
toolBarComposite = new Composite(parent, SWT.NONE);
gridLayout = new GridLayout(1, false);
toolBarComposite.setLayout(gridLayout);
gridData = new GridData(SWT.RIGHT, SWT.NONE, true, false);
toolBarComposite.setLayoutData(gridData);
// Create Toolbar
gridData = new GridData(SWT.RIGHT, SWT.NONE, true, false);
toolBar = new ToolBar(toolBarComposite, SWT.FLAT);
toolBar.setLayoutData(gridData);
// Create Item
item = new ToolItem(toolBar, SWT.PUSH);
item.setImage(SAVE_IMAGE);
item.setToolTipText("Save (Ctrl + S)");
item.setEnabled(true);
item.addSelectionListener(new SelectionAdapter() {
private static final long serialVersionUID = -102212312093090431L;
#Override
public void widgetSelected(SelectionEvent e) {
}
#Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
Thank for your advance !
You're going to have to use contributions on the view site's action bar.
Example
// Copy-pasted from an existing project, so the code can be made nicer
private void createAdditionalToolbarActions()
{
getViewSite().getActionBars().getToolBarManager().add(new GroupMarker("additions")); //$NON-NLS-1$
getViewSite().getActionBars().getToolBarManager().prependToGroup("additions", new SaveAction()); //$NON-NLS-1$
getViewSite().getActionBars().updateActionBars();
}
The method getViewSite is part of ViewPart. Call this after the contents of the view have been created.
The SaveAction must implement IAction or IContributionItem. For convenience, just extend the SaveAction from org.eclipse.jface.action.Action and call methods such as setImageDescriptor and setToolTipText.
Do all your business login in the run override.

JFace SourceViewer - AnnotationPainter for widgets

I want to add some SWT controls into SourceViewer.
Currently i am using AnnotainerPainter. It looks fine, except one thing and that is i don't know how to dispose the controls when the annotation is removed, because the AnnotationerPainter doesn't provide any info to
ITextStyleStrategy instance about what annotation it is processing (in that case i could just add the SWT control to it and later remove it when the annotation is going to be removed from AnnotationModel).
painter.addTextStyleStrategy("CONTROL", new AnnotationPainter.ITextStyleStrategy() {
private SourceViewer fViewer = ClassSourceViewer.this;
#Override
public void applyTextStyle(StyleRange styleRange, Color annotationColor) {
// TODO Auto-generated method stub
System.out.println(styleRange.start);
System.out.println(styleRange.length);
final Button button = new Button(fViewer.getTextWidget(), SWT.PUSH);
button.setFont(new Font(Display.getCurrent(), "Tahoma", 7, SWT.NORMAL));
button.setText("jmp to 24");
button.setBackground(fViewer.getTextWidget().getBackground());
button.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
button.dispose();
((AnnotationModel) fViewer.getAnnotationModel()).removeAllAnnotations();
}
});
button.pack();
button.setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_HAND));
Rectangle rect = button.getBounds();
int ascent = 2*rect.height/3;
int descent = rect.height - ascent;
button.setLocation(fViewer.getTextWidget().getLocationAtOffset(styleRange.start));
styleRange.metrics = new GlyphMetrics(ascent, descent,rect.width);
//styleRange.foreground = new Color(Display.getCurrent(), 0, 0, 0);
//styleRange.
//styleRange.background = new Color(Display.getCurrent(), 255, 255, 0);
}
});

CoolBar (java SWT WindowBuilder) Composite doesn't appear in Application

I have a problem when I try to use a coolBar in a composite and then I embed this composite in an application. The coolBar simply doesn't appear. This problem doesn't occours with another tools, like toolBar and other composites. What can I doing wrong or forgetting?
Before following the code, I refer my system:
Win7
Eclipse:Version: Indigo Service Release 2 Build id: 20120216-1857
Google WindowBuilder 1.5.0 Google
Plugin 3.1.0
SWT Designer 1.5.0
Google Web Toolkit 2.4.0
Composite code:
package xx.xxx.xx.pcommJavaGUI.composites;
import org.eclipse.swt.widgets.Composite;
public class TestComposite extends Composite {
public TestComposite(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout(1, false));
CoolBar coolBar = new CoolBar(this, SWT.FLAT);
CoolItem coolItem = new CoolItem(coolBar, SWT.NONE);
Button btnTest = new Button(coolBar, SWT.NONE);
coolItem.setControl(btnTest);
btnTest.setText("Test");
Tree tree = new Tree(this, SWT.BORDER);
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
}
#Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
And the application Window code:
package xx.xxx.xx.pcommJavaGUI.composites;
import org.eclipse.swt.SWT;
public class TestApplication {
protected Shell shell;
public static void main(String[] args) {
try {
TestApplication window = new TestApplication();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
shell.setLayout(new GridLayout(1, false));
TestComposite tc = new TestComposite(shell, SWT.NONE);
GridData gd_tc = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
tc.setLayoutData(gd_tc);
}
}
Thanks for helping.
You have to set the size of CoolItem manually.
First of all pack(); your Button to set it to it's default size.
Afterwards set the size of the CoolItem to the size of the Button.
The Button:
Button btnTest = new Button(coolBar, SWT.NONE);
coolItem.setControl(btnTest);
btnTest.setText("Test");
// If you do not call this, btnTest.getSize() will give you x=0,y=0.
btnTest.pack();
Set the size of CoolItem:
Point size = btnTest.getSize();
coolItem.setControl(btnTest);
coolItem.setSize(coolItem.computeSize(size.x, size.y));
Links:
CoolBar Examples
API: Control.pack();
It might be just because you aren't setting layout data for the coolbar. See this article to understand how layouts work.

ExpandBar in Eclipse View Part

I am trying to add an expand bar to an Eclipse viewpart. When I click the expand button I would like the viewpart to move items below the expand bar down and show the expanded items. What currently happens is the expand bar items just disappear below the items below the expand bar. Any thoughts?
final ExpandBar expandBar = new ExpandBar(parent, SWT.NONE);
expandBar.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
expandBar.setSpacing(0);
fd_toolBar.top = new FormAttachment(expandBar, 6);
FormData fd_expandBar = new FormData();
fd_expandBar.top = new FormAttachment(0, 62);
fd_expandBar.left = new FormAttachment(0, 3);
expandBar.setLayoutData(fd_expandBar);
formToolkit.paintBordersFor(expandBar);
final ExpandItem xpndtmWarningDetails = new ExpandItem(expandBar, SWT.NONE);
xpndtmWarningDetails.setExpanded(true);
xpndtmWarningDetails.setText("Warning Details");
final Composite composite_1 = new Composite(expandBar, SWT.NONE);
composite_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
xpndtmWarningDetails.setControl(composite_1);
formToolkit.paintBordersFor(composite_1);
xpndtmWarningDetails.setHeight(xpndtmWarningDetails.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
Label lblTest = new Label(composite_1, SWT.NONE);
lblTest.setBounds(10, 10, 55, 15);
lblTest.setText("Test");
expandBar.addExpandListener(new ExpandListener(){
#Override
public void itemCollapsed(ExpandEvent e) {
expandBar.setSize(expandBar.getSize().x, xpndtmWarningDetails.getHeaderHeight());
parent.layout(true);
}
#Override
public void itemExpanded(ExpandEvent e) {
expandBar.setSize(expandBar.getSize().x, 300);
expandBar.layout(true);
parent.layout(true);
}
});
I think the ExpandBar works best when used like it is in this example...
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet343.java
... with several expand bars stacked on top of each other, and nothing else mixed in.
I think the functionality your looking for can be accomplished with an ExpandableComposite object. It depends on what else is going on in your ViewPart.
Here's a quick example of an ExpandableComposite.
package com.amx.designsuite.rcp;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
public class ExpandableCompositeExample extends Composite {
/**
* Create the composite.
* #param parent
* #param style
*/
public ExpandableCompositeExample(final Composite parent, int style) {
super(parent, style);
FormToolkit toolkit;
toolkit = new FormToolkit(parent.getDisplay());
final ScrolledForm form = toolkit.createScrolledForm(parent);
form.setText("Title for Form holding Expandable Composite (optional)");
TableWrapLayout layout = new TableWrapLayout();
form.getBody().setLayout(layout);
ExpandableComposite expandableCompsite = toolkit.createExpandableComposite(form.getBody(), ExpandableComposite.TREE_NODE | ExpandableComposite.SHORT_TITLE_BAR);
toolkit.paintBordersFor(expandableCompsite);
expandableCompsite.setText("Expandable Composite Title (Optional)");
expandableCompsite.setExpanded(true);
Text txtMyNewText = toolkit.createText(expandableCompsite, "Text to show when composite is expanded", SWT.NONE);
expandableCompsite.setClient(txtMyNewText);
}
#Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}