Home » Eclipse Projects » Eclipse Scout » How to switch outlines with SWT
| |
Re: How to switch outlines with SWT [message #1003906 is a reply to message #1003854] |
Tue, 22 January 2013 08:04 |
Urs Beeli Messages: 573 Registered: October 2012 Location: Bern, Switzerland |
Senior Member |
|
|
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 10:08 |
Urs Beeli Messages: 573 Registered: October 2012 Location: Bern, Switzerland |
Senior Member |
|
|
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 10:08] Report message to a moderator
|
|
| | | | | | | | | | |
Re: How to switch outlines with SWT [message #1006158 is a reply to message #1006135] |
Wed, 30 January 2013 09:30 |
Urs Beeli Messages: 573 Registered: October 2012 Location: Bern, Switzerland |
Senior Member |
|
|
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...
|
|
|
Re: How to switch outlines with SWT [message #1006167 is a reply to message #1006158] |
Wed, 30 January 2013 10:30 |
Jeremie Bresson Messages: 1252 Registered: October 2011 |
Senior Member |
|
|
Thanks a lot for the time you took to investigate this.
I will update my example application with your code.
Urs Beeli wrote on Wed, 30 January 2013 10:30Just 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...
That a good question.
One of the big problem is (with Eclipse 3.x):
When the coolbar (Eclipse RCP) is populated, the Scout Model of the Application is not available.
With Eclipse 4.x, it should no longer be a problem (you can add and remove stuff in the E4 Application model when you want).
Second aspect to consider:
Not everybody wants the different outline represented in the RCP coolbar.
In my opinion the coolbar is really near the the button bar we have in the SWING application, so it would make sense.
But other projects use SWT Scout application embedded in Lotus Notes (as lotus notes plugin/extensions) or with additional UI Guideline.
It is possible to represent the Scout Outline as RCP Perspective or as Beat show in this thread with SnapBox.
I think it is difficult to provide something that works for everybody.
[Updated on: Wed, 30 January 2013 10:34] Report message to a moderator
|
|
| | |
Goto Forum:
Current Time: Wed Sep 25 11:04:16 GMT 2024
Powered by FUDForum. Page generated in 0.03980 seconds
|