ControlContribution & Separator on Toolbar [message #466121] |
Sat, 14 April 2007 11:51 |
michael Messages: 44 Registered: July 2009 |
Member |
|
|
If I put a Separator between two ControlContribution's in a view toolbar, each control's height on the toolbar becomes too small to see the control.
View Code:
final IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
toolBarManager.add(new MagnifyWithGridContribution("magnifyGrid", parent));
toolBarManager.add(new Separator());
toolBarManager.add(new MagnifyComboContribution("magnifyValue", parent));
ControlContribution code:
import org.eclipse.jface.action.ControlContribution;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.plugin.AbstractUIPlugin;
public class MagnifyComboContribution extends ControlContribution {
private final Composite notifyComposite;
private Composite c;
public MagnifyComboContribution(final String id, final Composite notifyComposite) {
super(id);
this.notifyComposite = notifyComposite;
}
@Override
protected Control createControl(Composite parent) {
c = new Composite(parent, SWT.BORDER);
c.setLayout(new GridLayout(2, false));
((GridLayout) c.getLayout()).horizontalSpacing = 0;
((GridLayout) c.getLayout()).verticalSpacing = 0;
((GridLayout) c.getLayout()).marginHeight = 0;
((GridLayout) c.getLayout()).marginWidth = 0;
final Label l = new Label(c, SWT.NONE);
final GridData data = new GridData();
data.widthHint = 26;
l.setLayoutData(data);
l.setImage(AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID,
IImageKeys.MAGNIFY_2).createImage());
final Combo combo = new Combo(c, SWT.NONE | SWT.DROP_DOWN | SWT.READ_ONLY);
combo
.setItems(new String[] { "1", "2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "22" });
combo.setSelection(new Point(100, 1000));
combo.setTextLimit(5);
combo.setText("6");
Event event = new Event();
event.data = "magnify";
event.widget = combo;
notifyComposite.notifyListeners(SWT.Modify, event);
//combo.setToolTipText(getId());
combo.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
Event event = new Event();
event.data = new Object[] {"magnify", combo };
notifyComposite.notifyListeners(SWT.Modify, event);
}
});
return c;
}
}
import org.eclipse.jface.action.ControlContribution;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
public class MagnifyWithGridContribution extends ControlContribution {
private final Composite notifyComposite;
public MagnifyWithGridContribution(final String id, final Composite notifyComposite) {
super(id);
this.notifyComposite = notifyComposite;
}
@Override
protected Control createControl(Composite parent) {
final Button b = new Button(parent, SWT.BORDER | SWT.CHECK | SWT.CENTER);
b.setText("Grid (" + "\u2265" + "4%) ");
b.addSelectionListener(new SelectionListener() {
Event event = new Event();
public void widgetDefaultSelected(final SelectionEvent e) {
}
public void widgetSelected(final SelectionEvent e) {
event.data = new Object[] { "magnify", b };
notifyComposite.notifyListeners(SWT.Modify, event);
}
});
return b;
}
}
|
|
|
|
Re: ControlContribution & Separator on Toolbar [message #466127 is a reply to message #466123] |
Sat, 14 April 2007 22:05 |
Eclipse User |
|
|
|
Originally posted by: bugjester.yahoo.com
I had a similar problem a long time ago (I think it was related more to
width than height). I can't remember exactly what I did to fix it, and
I don't have access to that code any more, but I seem to remember
wrapping some of the controls in ToolItem objects. You might try some
experiments like the following:
protected Control createControl(Composite parent)
{
final Button b = new Button(parent,
SWT.BORDER | SWT.CHECK | SWT.CENTER);
b.setText(...);
ToolItem toolItem = new ToolItem((ToolBar)parent, SWT.NONE);
toolItem.setControl(b);
...
return b;
}
Hope that helps a little.
Steve
michael wrote:
> If I put a Separator between two ControlContribution's in a view
toolbar, each control's height on the toolbar becomes too small to see
the control.
....
> public class MagnifyWithGridContribution extends ControlContribution {
>
> private final Composite notifyComposite;
>
> public MagnifyWithGridContribution(final String id, final Composite
notifyComposite) {
> super(id);
> this.notifyComposite = notifyComposite;
> }
>
> @Override
> protected Control createControl(Composite parent) {
> final Button b = new Button(parent, SWT.BORDER | SWT.CHECK |
SWT.CENTER);
> b.setText("Grid (" + "\u2265" + "4%) ");
> b.addSelectionListener(new SelectionListener() {
> Event event = new Event();
>
> public void widgetDefaultSelected(final SelectionEvent e) {
> }
>
> public void widgetSelected(final SelectionEvent e) {
> event.data = new Object[] { "magnify", b };
> notifyComposite.notifyListeners(SWT.Modify, event);
> }
> });
>
> return b;
> }
> }
> [/code]
|
|
|
Powered by
FUDForum. Page generated in 0.04393 seconds