Skip to content

Commit a4f013b

Browse files
committed
Also added the save and restore perspective handling in the sampel app
Change-Id: Ib307b58e1b468fc3d0a4cfdd6aba36eb47f7cd10 Signed-off-by: Simon Scholz <simon.scholz@vogella.com>
1 parent 6490712 commit a4f013b

4 files changed

Lines changed: 113 additions & 3 deletions

File tree

com.vogella.rcp.jface.translation/Application.e4xmi

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2010/UIModel/application" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic" xmi:id="_FstfcGsgEeSnK-CHgGDtvQ" elementId="org.eclipse.e4.ide.application" bindingContexts="_FstfeWsgEeSnK-CHgGDtvQ">
2+
<application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:advanced="http://www.eclipse.org/ui/2010/UIModel/application/ui/advanced" xmlns:application="http://www.eclipse.org/ui/2010/UIModel/application" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_FstfcGsgEeSnK-CHgGDtvQ" elementId="org.eclipse.e4.ide.application" bindingContexts="_FstfeWsgEeSnK-CHgGDtvQ">
33
<children xsi:type="basic:TrimmedWindow" xmi:id="_FstfcWsgEeSnK-CHgGDtvQ" label="WizardTranslation" width="500" height="400">
4-
<children xsi:type="basic:PartStack" xmi:id="_FsuGimsgEeSnK-CHgGDtvQ">
5-
<children xsi:type="basic:Part" xmi:id="_FsutkGsgEeSnK-CHgGDtvQ" contributionURI="bundleclass://com.vogella.rcp.jface.translation/wizardtranslation.parts.SamplePart" label="Sample Part"/>
4+
<children xsi:type="advanced:PerspectiveStack" xmi:id="_mpFZAGwUEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.perspectivestack.0">
5+
<children xsi:type="advanced:Perspective" xmi:id="_m8rqcGwUEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.perspective.main" label="Main Perspective">
6+
<children xsi:type="basic:PartStack" xmi:id="_FsuGimsgEeSnK-CHgGDtvQ">
7+
<children xsi:type="basic:Part" xmi:id="_FsutkGsgEeSnK-CHgGDtvQ" contributionURI="bundleclass://com.vogella.rcp.jface.translation/wizardtranslation.parts.SamplePart" label="Sample Part"/>
8+
</children>
9+
<children xsi:type="basic:PartStack" xmi:id="_Eoc6UGwWEeSqHfYvWOYz-Q">
10+
<children xsi:type="basic:Part" xmi:id="_Eoc6UWwWEeSqHfYvWOYz-Q" contributionURI="bundleclass://com.vogella.rcp.jface.translation/wizardtranslation.parts.SamplePart" label="Sample Part"/>
11+
</children>
12+
</children>
13+
<children xsi:type="advanced:Perspective" xmi:id="_qSHVMGwUEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.perspective.second" label="Second Perspective">
14+
<children xsi:type="basic:PartSashContainer" xmi:id="_7d-HwGwVEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.partsashcontainer.0">
15+
<children xsi:type="basic:PartStack" xmi:id="_vEoB8GwUEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.partstack.0">
16+
<children xsi:type="basic:Part" xmi:id="_vVXzsGwUEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.part.secondPerspectivePart" label="Second Perspective Part"/>
17+
</children>
18+
<children xsi:type="basic:PartStack" xmi:id="_9sw6kGwVEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.partstack.1">
19+
<children xsi:type="basic:Part" xmi:id="_9_sdoGwVEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.part.moveOrCloseMe" label="Move or close me" closeable="true"/>
20+
</children>
21+
</children>
22+
</children>
623
</children>
24+
<mainMenu xmi:id="_4CIIcGwUEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.menu.0">
25+
<children xsi:type="menu:Menu" xmi:id="_5xemMGwUEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.menu.window" label="Window">
26+
<children xsi:type="menu:HandledMenuItem" xmi:id="_8C09wGwUEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.handledmenuitem.0" command="__mG3QGwUEeSqHfYvWOYz-Q"/>
27+
<children xsi:type="menu:HandledMenuItem" xmi:id="_spjRMGwVEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.handledmenuitem.1" command="_DmwesGwUEeSqHfYvWOYz-Q"/>
28+
<children xsi:type="menu:HandledMenuItem" xmi:id="_tsvMgGwVEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.handledmenuitem.2" command="_GYFW0GwUEeSqHfYvWOYz-Q"/>
29+
</children>
30+
</mainMenu>
731
</children>
32+
<handlers xmi:id="_IniQ8GwUEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.handler.0" contributionURI="bundleclass://com.vogella.rcp.jface.translation/wizardtranslation.handlers.SavePerspectiveHandler" command="_DmwesGwUEeSqHfYvWOYz-Q"/>
33+
<handlers xmi:id="_aCsgQGwUEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.handler.1" contributionURI="bundleclass://com.vogella.rcp.jface.translation/wizardtranslation.handlers.RestorePerspectiveHandler" command="_GYFW0GwUEeSqHfYvWOYz-Q"/>
34+
<handlers xmi:id="_-h8EgGwUEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.handler.2" contributionURI="bundleclass://com.vogella.rcp.jface.translation/wizardtranslation.handlers.SwitchPerspectiveHandler" command="__mG3QGwUEeSqHfYvWOYz-Q"/>
835
<bindingTables xmi:id="_FstffmsgEeSnK-CHgGDtvQ" bindingContext="_FstfeWsgEeSnK-CHgGDtvQ">
936
<bindings xmi:id="_Fstff2sgEeSnK-CHgGDtvQ" keySequence="M1+Q"/>
1037
<bindings xmi:id="_FstfgmsgEeSnK-CHgGDtvQ" keySequence="M1+O"/>
@@ -15,6 +42,9 @@
1542
<children xmi:id="_FstfemsgEeSnK-CHgGDtvQ" elementId="org.eclipse.ui.contexts.window" name="In Windows"/>
1643
<children xmi:id="_Fstfe2sgEeSnK-CHgGDtvQ" elementId="org.eclipse.ui.contexts.dialog" name="In Dialogs"/>
1744
</rootContext>
45+
<commands xmi:id="_DmwesGwUEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.command.saveperspective" commandName="Save Perspective"/>
46+
<commands xmi:id="_GYFW0GwUEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.command.restoreperspective" commandName="Restore Perspective"/>
47+
<commands xmi:id="__mG3QGwUEeSqHfYvWOYz-Q" elementId="com.vogella.rcp.jface.translation.command.switchPerspective" commandName="Switch Perspective"/>
1848
<addons xmi:id="_FstfcmsgEeSnK-CHgGDtvQ" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/>
1949
<addons xmi:id="_Fstfc2sgEeSnK-CHgGDtvQ" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/>
2050
<addons xmi:id="_FstfdGsgEeSnK-CHgGDtvQ" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package wizardtranslation.handlers;
2+
3+
import org.eclipse.e4.core.di.annotations.CanExecute;
4+
import org.eclipse.e4.core.di.annotations.Execute;
5+
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
6+
import org.eclipse.e4.ui.model.application.ui.MUIElement;
7+
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
8+
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
9+
import org.eclipse.e4.ui.workbench.modeling.EModelService;
10+
import org.eclipse.e4.ui.workbench.modeling.EPartService;
11+
12+
public class RestorePerspectiveHandler {
13+
@Execute
14+
public void execute(EModelService modelService, MWindow window,
15+
EPartService partService) {
16+
MPerspective activePerspective = modelService
17+
.getActivePerspective(window);
18+
MUIElement findSnippet = modelService.findSnippet(window,
19+
activePerspective.getElementId());
20+
MElementContainer<MUIElement> parent = activePerspective.getParent();
21+
modelService.removePerspectiveModel(activePerspective, window);
22+
parent.getChildren().add(findSnippet);
23+
partService.switchPerspective((MPerspective) findSnippet);
24+
}
25+
26+
27+
@CanExecute
28+
public boolean canExecute(EModelService modelService, MWindow window) {
29+
MPerspective activePerspective = modelService
30+
.getActivePerspective(window);
31+
return modelService.findSnippet(window,
32+
activePerspective.getElementId()) != null;
33+
}
34+
35+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package wizardtranslation.handlers;
2+
3+
import org.eclipse.e4.core.di.annotations.Execute;
4+
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
5+
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
6+
import org.eclipse.e4.ui.workbench.modeling.EModelService;
7+
8+
public class SavePerspectiveHandler {
9+
@Execute
10+
public void execute(EModelService modelService, MWindow window) {
11+
MPerspective activePerspective = modelService
12+
.getActivePerspective(window);
13+
modelService.cloneElement(activePerspective, window);
14+
}
15+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
package wizardtranslation.handlers;
3+
4+
5+
import java.util.List;
6+
7+
import org.eclipse.e4.core.di.annotations.Execute;
8+
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
9+
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
10+
import org.eclipse.e4.ui.workbench.modeling.EModelService;
11+
import org.eclipse.e4.ui.workbench.modeling.EPartService;
12+
13+
public class SwitchPerspectiveHandler {
14+
@Execute
15+
public void execute(EModelService modelService, EPartService partService,
16+
MWindow window) {
17+
MPerspective activePerspective = modelService
18+
.getActivePerspective(window);
19+
20+
List<MPerspective> perspectives = modelService.findElements(window,
21+
null, MPerspective.class, null);
22+
23+
for (MPerspective perspective : perspectives) {
24+
if (!perspective.equals(activePerspective)) {
25+
partService.switchPerspective(perspective);
26+
}
27+
}
28+
}
29+
30+
}

0 commit comments

Comments
 (0)