How to switch outlines with SWT [message #1003553] |
Mon, 21 January 2013 09:04  |
Eclipse User |
|
|
|
The Swing client automatically provides buttons to switch between defined outlines. The SWT client does not provide these buttons. I have looked into various solutions to this and have found a few ways to do this:
- adding a menu Outline to the Desktop and then adding a submenu for each outline; in execAction set the outline using
setOutline(StandardOutline.class)
- adding an OutlineButton to a form and configuring it using its getConfiguredOutline() method
Both methods sort of work (I occasionally loose the table view when switching outlines) but neither of them is as elegant as having those buttons above the outline tree view in Swing.
Is there an easy way to replicate this behaviour in an SWT client? In another thread, somebody mentioned that this is what SnapBoxes were for, but I have no idea how I would display one of those outside a form.
|
|
|
|
Re: How to switch outlines with SWT [message #1003906 is a reply to message #1003854] |
Tue, 22 January 2013 03:04   |
Eclipse User |
|
|
|
Jeremie Bresson wrote on Tue, 22 January 2013 07:10Quote:In another thread, somebody mentioned that this is what SnapBoxes were for
Please if you mention an other forum thread, add a link to it:
How to use SnapBox
Sorry, I was going to but then forgot to do so before posting.
Jeremie Bresson wrote on Tue, 22 January 2013 07:10Is your question not a duplicate of this one ?
[SWT GUI] switch between outlines attached to the desktop?
It is indeed, I must have missed that post when looking through the forum, sorry.
Jeremie Bresson wrote on Tue, 22 January 2013 07:10With this method, you have to programm the Coolbar directly in the SWT Plugin. You need to ensure manually that your code match with the Scout Client Model (If you add an outline for example).
I'll have a look at the two links in the post you quoted above to see if I manage to make it work, thanks for pointing me in the right direction.
|
|
|
|
|
Re: How to switch outlines with SWT [message #1004472 is a reply to message #1004024] |
Wed, 23 January 2013 05:08   |
Eclipse User |
|
|
|
Thanks for this pointer. I had not realised that there was an ApplicationActionBarAdvisor class already in my SWT project 
I have now added the code from your example (which closely matches the code in the RCP tutorial I linked above). Unfortunately, it throws an exception when I am trying to add the ToolBarContributionItem to the coolBar depending on the id string used to create the ToolBarContributionItem:
@Override
protected void fillCoolBar(ICoolBarManager coolBar) {
IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
ToolBarContributionItem tbci = new ToolBarContributionItem(toolbar, "org.eclipse.ui.main.toolbar"); // using this string, causes an exception below
//ToolBarContributionItem tbci = new ToolBarContributionItem(toolbar, "toolbar"); // using this string, no exception is thrown, but no toolbar shown either
coolBar.add(tbci); // this line throws an exception with the long string
toolbar.add(standardAction);
toolbar.add(administrationAction);
}
If I change the id-string to just "toolbar", no exception is thrown, but no toolbar is shown, either. Any ideas on how to proceed?
The exception is:
!MESSAGE Exception occurred while rendering: org.eclipse.e4.ui.model.application.ui.basic.impl.TrimmedWindowImpl@44534453 (elementId: IDEWindow, tags: [topLevel], contributorURI: platform:/plugin/org.eclipse.platform) (widget: Shell {minicrm}, renderer: org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer@ca30ca3, toBeRendered: true, onTop: false, visible: true, containerData: null, accessibilityPhrase: null) (label: %trimmedwindow.label.eclipseSDK, iconURI: null, tooltip: null, context: TrimmedWindowImpl (IDEWindow) Context, variables: [], x: -2147483648, y: -2147483648, width: 1024, height: 768)
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.ClassCastException: org.eclipse.e4.ui.model.application.ui.basic.impl.TrimBarImpl incompatible with org.eclipse.e4.ui.model.application.ui.menu.MToolBar
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:859)
at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:111)
at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:81)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.inject(ContextInjectionFactory.java:72)
at org.eclipse.ui.internal.Workbench.createWorkbenchWindow(Workbench.java:1252)
at org.eclipse.ui.internal.Workbench.getActiveWorkbenchWindow(Workbench.java:1224)
at org.eclipse.ui.internal.services.WorkbenchSourceProvider.updateActiveShell(WorkbenchSourceProvider.java:924)
at org.eclipse.ui.internal.services.WorkbenchSourceProvider.getCurrentState(WorkbenchSourceProvider.java:133)
at org.eclipse.ui.internal.services.WorkbenchSourceProvider$6.handleEvent(WorkbenchSourceProvider.java:684)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1262)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1058)
at org.eclipse.swt.widgets.Decorations.WM_ACTIVATE(Decorations.java:1664)
at org.eclipse.swt.widgets.Shell.WM_ACTIVATE(Shell.java:2145)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4525)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1627)
at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2069)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4976)
at org.eclipse.swt.internal.win32.OS.BringWindowToTop(Native Method)
at org.eclipse.swt.widgets.Decorations.bringToTop(Decorations.java:231)
at org.eclipse.swt.widgets.Shell.open(Shell.java:1217)
at org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer.postProcess(WBWRenderer.java:730)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:646)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:732)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$2(PartRenderingEngine.java:703)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$7.run(PartRenderingEngine.java:697)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:682)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:964)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:923)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.minicrm.ui.swt.application.Application.startSecure(Application.java:43)
at org.eclipse.minicrm.ui.swt.application.Application$1.run(Application.java:35)
at java.security.AccessController.doPrivileged(AccessController.java:284)
at javax.security.auth.Subject.doAs(Subject.java:573)
at org.eclipse.minicrm.ui.swt.application.Application.start(Application.java:32)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.ClassCastException: org.eclipse.e4.ui.model.application.ui.basic.impl.TrimBarImpl incompatible with org.eclipse.e4.ui.model.application.ui.menu.MToolBar
at org.eclipse.ui.internal.CoolBarToTrimManager.add(CoolBarToTrimManager.java:130)
at org.eclipse.ui.internal.CoolBarToTrimManager.add(CoolBarToTrimManager.java:115)
at org.eclipse.minicrm.ui.swt.application.ApplicationActionBarAdvisor.fillCoolBar(ApplicationActionBarAdvisor.java:59)
at org.eclipse.ui.application.ActionBarAdvisor.fillActionBars(ActionBarAdvisor.java:154)
at org.eclipse.ui.internal.WorkbenchWindow.fillActionBars(WorkbenchWindow.java:2058)
at org.eclipse.ui.internal.WorkbenchWindow.setup(WorkbenchWindow.java:533)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
... 57 more
[Updated on: Wed, 23 January 2013 05:08] by Moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: How to switch outlines with SWT [message #1006158 is a reply to message #1006135] |
Wed, 30 January 2013 04:30   |
Eclipse User |
|
|
|
Ok, I've now compiled and run the BahBah example with the same target settings as my project and there I can see the toolbar in the SWT client. So I compared the code of the two projects and found why mine didn't show the toolbar: In my ApplicationWorkbenchWindowAdvisor.preWindowOpen() method there was a line:
configurer.setShowCoolBar(false);
After changing this to true, the bar displays. I have also modified the BahBah code so the toolbar not only displays the OutlineViewButtons but the buttons added to the desktops toolbar.
As this question has been asked a few times, here is a summary with all the changes I needed to make to show the outline change buttons on the SWT toolbar:
<package-base-path>.ui.swt\SwtEnvironment.java
-> add member
private ApplicationActionBarAdvisor m_advisor;
-> modify the addEnvironmentListener as follows:
addEnvironmentListener(new ISwtEnvironmentListener() {
@Override
public void environmentChanged(SwtEnvironmentEvent e) {
if (e.getType() == SwtEnvironmentEvent.STARTED) {
removeEnvironmentListener(this);
IDesktop d = getClientSession().getDesktop();
if (d != null) {
setWindowTitle(d.getTitle());
d.addPropertyChangeListener(IDesktop.PROP_TITLE, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
setWindowTitle((String) evt.getNewValue());
}
});
m_advisor.initViewButtons(d); // --> add this line
}
}
}
});
}
-> add method setAdvisor
public void setAdvisor(ApplicationActionBarAdvisor advisor) {
m_advisor = advisor;
}
<package-base-path>.ui.swt.application\ApplicationWorkbenchWindowAdvisor
-> in preWindowOpen, change the line
configurer.setShowCoolBar(true);
to
configurer.setShowCoolBar(true);
<package-base-path>.ui.swt.application\CoolbarButton
-> create a new class
package <package-base-path>.ui.swt.application;
import org.eclipse.jface.action.Action;
import org.eclipse.minicrm.ui.swt.Activator;
import org.eclipse.scout.rt.client.ui.action.IAction;
/**
*
*/
public class CoolbarButton extends Action {
private IAction m_button;
public CoolbarButton() {
setText(" ");
setEnabled(false);
}
public void init(IAction b) {
setText(b.getText());
setId(b.getActionId());
setActionDefinitionId(b.getActionId());
setToolTipText(b.getTooltipText());
setImageDescriptor(Activator.getDefault().getEnvironment().getImageDescriptor(b.getIconId()));
m_button = b;
}
@Override
public void run() {
Runnable r = new Runnable() {
@Override
public void run() {
m_button.setSelected(true);
m_button.getUIFacade().fireActionFromUI();
}
};
Activator.getDefault().getEnvironment().invokeScoutLater(r, 10000);
}
}
<package-base-path>.ui.swt.application\ApplicationActionBarAdvisor
-> add members
private static final int NUM_OUTLINE_BUTTONS = 10; // --> make this big enough to fit all your outline and toolbar buttons
private CoolbarButton[] m_coolbarButton = new CoolbarButton[NUM_OUTLINE_BUTTONS];
-> add the following line to the constructor
public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
super(configurer);
((SwtEnvironment) Activator.getDefault().getEnvironment()).setAdvisor(this); // --> add this line
}
-> add the following methods
@Override
protected void makeActions(IWorkbenchWindow window) {
for (int i = 0; i < NUM_OUTLINE_BUTTONS; i++) {
m_coolbarButton[i] = new CoolbarButton();
}
}
public void initViewButtons(IDesktop d) {
IViewButton[] viewButtons = d.getViewButtons();
int start = 0;
int end = Math.min(m_coolbarButton.length, viewButtons.length);
for (int i = start; i < end; i++) {
CoolbarButton b = m_coolbarButton[i];
IViewButton v = viewButtons[i];
b.setEnabled(v.isEnabled() && v.isEnabledGranted());
if (v.isVisible() && v.isVisibleGranted()) {
b.init(v);
register(b);
}
else {
b.setEnabled(false);
}
}
IToolButton[] toolButtons = d.getToolButtons();
start = end + 1;
end = Math.min(m_coolbarButton.length, start + toolButtons.length);
for (int i = start; i < end; i++) {
CoolbarButton b = m_coolbarButton[i];
IToolButton v = toolButtons[i - start];
b.setEnabled(v.isEnabled() && v.isEnabledGranted());
if (v.isVisible() && v.isVisibleGranted()) {
b.init(v);
register(b);
}
else {
b.setEnabled(false);
}
}
}
@Override
protected void fillCoolBar(ICoolBarManager coolBar) {
IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
coolBar.add(new ToolBarContributionItem(toolbar, "main"));
for (Action a : m_coolbarButton) {
toolbar.add(a);
}
}
Thanks to everyone who helped me get this far, I really appreciated your help!
Just out of curiosity: Is there a reason why the above code is not generated by default? I see the issue of the magic array size being dependent on the number of buttons added in the client, but that could be chosen big enough to hold quite a few as a start...
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07597 seconds