Dynamic CoolBar Contributions Using JFace [message #187201] |
Fri, 30 January 2004 10:28  |
Eclipse User |
|
|
|
Originally posted by: news.eclipse.org.VictorLewisIII.com
I am using JFace in a stand alone application (does not run inside
Eclipse). I would like to have various options on the CoolBar appear or
hide depending on what is selected in the UI. The CoolBar managers
are not behaving the way I expect them to. It is not clear to me if
this is a bug with the CoolBar managers or if I am just using them
incorrectly.
The goal of the program below is to have the "Blue" items appear on the
CoolBar when the "Blue" button is pressed but go away and be replaced by
the "Red" CoolBar items when the red button is pressed. The actual
behavior is unpredictable, the items from the removed contributer are
there and can be pressed but are not always redrawn, sometimes the items
from the second contributer are displaced and sometimes not, other times
one will be painted over the other.
Please help. Is this a bug or am I going about this the wrong way?
Thank You,
Victor
package test;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.CoolBarManager;
import org.eclipse.jface.action.ToolBarContributionItem;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
public class CoolBarBug extends ApplicationWindow {
//This one only shows up when red button is pressed
ToolBarContributionItem redCoolBar = null;
//This one only shows up when blue button is pressed
ToolBarContributionItem blueCoolBar = null;
//This one is always there
ToolBarContributionItem alwaysCoolBar = null;
public CoolBarBug() {
super(null);
addCoolBar(SWT.NONE);
}
protected CoolBarManager createCoolBarManager(int style) {
CoolBarManager manager = super.createCoolBarManager(style);
manager.add(getAlwaysCoolBar());
return manager;
}
protected Control createContents(Composite parent) {
final Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new FillLayout());
final Button redButton = new Button(composite, SWT.NONE);
redButton.setText("Red");
redButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
System.out.println("Red selected");
getCoolBarManager().remove(getBlueCoolBar());
getCoolBarManager().add(getRedCoolBar());
getCoolBarManager().update(true);
}
public void widgetDefaultSelected(SelectionEvent e) { }
});
final Button blueButton = new Button(composite, SWT.NONE);
blueButton.setText("Blue");
blueButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
System.out.println("Blue selected");
getCoolBarManager().remove(getRedCoolBar());
getCoolBarManager().add(getBlueCoolBar());
getCoolBarManager().update(true);
}
public void widgetDefaultSelected(SelectionEvent e) { }
});
return composite;
}
ToolBarContributionItem getRedCoolBar() {
if (redCoolBar == null) {
final ToolBarManager toolBar = new ToolBarManager();
toolBar.add(new Action("Red One", SWT.NONE) {});
toolBar.add(new Action("Red Two", SWT.NONE) {});
toolBar.add(new Action("Red Three", SWT.NONE) {});
redCoolBar = new ToolBarContributionItem(toolBar, "red");
redCoolBar.setVisible(false);
}
return redCoolBar;
}
ToolBarContributionItem getBlueCoolBar() {
if (blueCoolBar == null) {
final ToolBarManager toolBar = new ToolBarManager();
toolBar.add(new Action("Blue", SWT.NONE) {});
blueCoolBar = new ToolBarContributionItem(toolBar, "blue");
blueCoolBar.setVisible(false);
}
return blueCoolBar;
}
ToolBarContributionItem getAlwaysCoolBar() {
if (alwaysCoolBar == null) {
final ToolBarManager toolBar = new ToolBarManager();
toolBar.add(new Action("Alywas Here", SWT.NONE) {});
alwaysCoolBar = new ToolBarContributionItem(toolBar,
"always");
}
return alwaysCoolBar;
}
public static void main(String[] args) {
CoolBarBug w = new CoolBarBug();
w.setBlockOnOpen(true);
w.open();
Display.getCurrent().dispose();
}
}
|
|
|
Re: Dynamic CoolBar Contributions Using JFace [message #188443 is a reply to message #187201] |
Mon, 02 February 2004 16:30  |
Eclipse User |
|
|
|
Originally posted by: news.eclipse.org.VictorLewisIII.com
Sorry to be a pain in the a** about this but would someone please help
me out here. I am really stuck on this. Can I at least get a pointer
as to why no one as answered my question.
a) Dude, your babblin'
b) Stupidest question every asked
c) You asked it in the wrong forum (if so where might be more appropriate?).
d) You post that much code and expect anyone to ready it . . . ya right.
Thanks,
Victor
Victor Lewis wrote:
> I am using JFace in a stand alone application (does not run inside
> Eclipse). I would like to have various options on the CoolBar appear or
> hide depending on what is selected in the UI. The CoolBar managers are
> not behaving the way I expect them to. It is not clear to me if this is
> a bug with the CoolBar managers or if I am just using them incorrectly.
>
> The goal of the program below is to have the "Blue" items appear on the
> CoolBar when the "Blue" button is pressed but go away and be replaced by
> the "Red" CoolBar items when the red button is pressed. The actual
> behavior is unpredictable, the items from the removed contributer are
> there and can be pressed but are not always redrawn, sometimes the items
> from the second contributer are displaced and sometimes not, other times
> one will be painted over the other.
>
> Please help. Is this a bug or am I going about this the wrong way?
>
> Thank You,
> Victor
>
> package test;
>
> import org.eclipse.jface.action.Action;
> import org.eclipse.jface.action.CoolBarManager;
> import org.eclipse.jface.action.ToolBarContributionItem;
> import org.eclipse.jface.action.ToolBarManager;
> import org.eclipse.jface.window.ApplicationWindow;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.events.SelectionListener;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Control;
> import org.eclipse.swt.widgets.Display;
>
> public class CoolBarBug extends ApplicationWindow {
> //This one only shows up when red button is pressed
> ToolBarContributionItem redCoolBar = null;
> //This one only shows up when blue button is pressed
> ToolBarContributionItem blueCoolBar = null;
> //This one is always there
> ToolBarContributionItem alwaysCoolBar = null;
>
> public CoolBarBug() {
> super(null);
> addCoolBar(SWT.NONE);
> }
>
> protected CoolBarManager createCoolBarManager(int style) {
> CoolBarManager manager = super.createCoolBarManager(style);
> manager.add(getAlwaysCoolBar());
>
> return manager;
> }
>
> protected Control createContents(Composite parent) {
> final Composite composite = new Composite(parent, SWT.NONE);
> composite.setLayout(new FillLayout());
> final Button redButton = new Button(composite, SWT.NONE);
> redButton.setText("Red");
> redButton.addSelectionListener(new SelectionListener() {
> public void widgetSelected(SelectionEvent e) {
> System.out.println("Red selected");
> getCoolBarManager().remove(getBlueCoolBar());
> getCoolBarManager().add(getRedCoolBar());
> getCoolBarManager().update(true);
> }
> public void widgetDefaultSelected(SelectionEvent e) { }
> });
> final Button blueButton = new Button(composite, SWT.NONE);
> blueButton.setText("Blue");
> blueButton.addSelectionListener(new SelectionListener() {
> public void widgetSelected(SelectionEvent e) {
> System.out.println("Blue selected");
> getCoolBarManager().remove(getRedCoolBar());
> getCoolBarManager().add(getBlueCoolBar());
> getCoolBarManager().update(true);
> }
> public void widgetDefaultSelected(SelectionEvent e) { }
> });
> return composite;
> }
>
> ToolBarContributionItem getRedCoolBar() {
> if (redCoolBar == null) {
> final ToolBarManager toolBar = new ToolBarManager();
> toolBar.add(new Action("Red One", SWT.NONE) {});
> toolBar.add(new Action("Red Two", SWT.NONE) {});
> toolBar.add(new Action("Red Three", SWT.NONE) {});
> redCoolBar = new ToolBarContributionItem(toolBar, "red");
> redCoolBar.setVisible(false);
> }
>
> return redCoolBar;
> }
>
> ToolBarContributionItem getBlueCoolBar() {
> if (blueCoolBar == null) {
> final ToolBarManager toolBar = new ToolBarManager();
> toolBar.add(new Action("Blue", SWT.NONE) {});
> blueCoolBar = new ToolBarContributionItem(toolBar, "blue");
> blueCoolBar.setVisible(false);
> }
>
> return blueCoolBar;
> }
>
> ToolBarContributionItem getAlwaysCoolBar() {
> if (alwaysCoolBar == null) {
> final ToolBarManager toolBar = new ToolBarManager();
> toolBar.add(new Action("Alywas Here", SWT.NONE) {});
> alwaysCoolBar = new ToolBarContributionItem(toolBar, "always");
> }
>
> return alwaysCoolBar;
> }
>
> public static void main(String[] args) {
> CoolBarBug w = new CoolBarBug();
> w.setBlockOnOpen(true);
> w.open();
> Display.getCurrent().dispose();
> }
> }
|
|
|
Powered by
FUDForum. Page generated in 0.03628 seconds