ref #6596 Enable "Save" icon when specimen editor is dirty
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 27 Jun 2017 09:03:54 +0000 (11:03 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 27 Jun 2017 12:32:51 +0000 (14:32 +0200)
eu.etaxonomy.taxeditor.workbench/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.workbench/fragment.e4xmi
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/SaveHandler.java

index 4e871d83b694bf1a14370982b0088903332f490b..41375d3e357914c308cf962a5bcd6f20d0be0c0a 100644 (file)
@@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.equinox.p2.metadata;bundle-version="2.3.100",
  org.eclipse.equinox.p2.operations;bundle-version="2.4.200",
  org.eclipse.e4.core.di,
- org.eclipse.e4.ui.services
+ org.eclipse.e4.ui.services,
+ org.eclipse.e4.core.commands
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Import-Package: javax.inject;version="1.0.0"
 Bundle-ActivationPolicy: lazy
index 0b0ee6d572b47aa0971e7fd5458ca15ec9fdc6b7..f9f2982160b72abd55bfa83ebc2be6bf0adc3f41 100644 (file)
@@ -78,7 +78,7 @@
     <elements xsi:type="menu:TrimContribution" xmi:id="_FIbzwB92EeeIA_2gwq7JKg" elementId="eu.etaxonomy.taxeditor.workbench.trimcontribution.mainToolbar" parentId="org.eclipse.ui.main.toolbar" positionInParent="after=additions">
       <children xsi:type="menu:ToolBar" xmi:id="_KDVngB92EeeIA_2gwq7JKg" elementId="eu.etaxonomy.taxeditor.workbench.menu.toolbar.0">
         <children xsi:type="menu:HandledToolItem" xmi:id="_KvxPsB92EeeIA_2gwq7JKg" elementId="eu.etaxonomy.taxeditor.workbench.menu.toolbar.new" label="%command.label.21" iconURI="platform:/plugin/org.eclipse.ui/icons/full/etool16/new_wiz.png" command="_hooiQB7QEeeC-JvycL9ysA"/>
-        <children xsi:type="menu:HandledToolItem" xmi:id="_ARn5AB96EeeIA_2gwq7JKg" elementId="eu.etaxonomy.taxeditor.workbench.menu.toolbar.save" label="%command.label.22" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/save_edit.gif" command="_PkWcQB62EeePLJ5to5QrXQ"/>
+        <children xsi:type="menu:HandledToolItem" xmi:id="_hnQUcFp0Eee4PsIXei-TMg" elementId="eu.etaxonomy.taxeditor.workbench.menu.toolbar.save" label="%command.label.22" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/save_edit.gif" command="_X-56IFp0Eee4PsIXei-TMg"/>
       </children>
     </elements>
   </fragments>
@@ -88,6 +88,7 @@
     <elements xsi:type="commands:Command" xmi:id="_LVTo8B62EeePLJ5to5QrXQ" elementId="org.eclipse.ui.file.close" commandName="%command.label"/>
     <elements xsi:type="commands:Command" xmi:id="_MrLPsB62EeePLJ5to5QrXQ" elementId="org.eclipse.ui.file.closeAll" commandName="%command.label.0"/>
     <elements xsi:type="commands:Command" xmi:id="_PkWcQB62EeePLJ5to5QrXQ" elementId="org.eclipse.ui.file.save" commandName="%command.label.1"/>
+    <elements xsi:type="commands:Command" xmi:id="_X-56IFp0Eee4PsIXei-TMg" elementId="eu.etaxonomy.taxeditor.workbench.save" commandName="%command.label.1"/>
     <elements xsi:type="commands:Command" xmi:id="_RWLmQB62EeePLJ5to5QrXQ" elementId="org.eclipse.ui.file.saveAll" commandName="%command.label.2"/>
     <elements xsi:type="commands:Command" xmi:id="_TvLd8B62EeePLJ5to5QrXQ" elementId="org.eclipse.ui.file.exit" commandName="%command.label.5"/>
     <elements xsi:type="commands:Command" xmi:id="_5pfmIB7DEeeRW_RHu3JLqQ" elementId="org.eclipse.ui.edit.undo" commandName="%command.label.6"/>
     <elements xsi:type="commands:Handler" xmi:id="_uzAhUCRAEeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.update.UpdateHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.update.UpdateHandler" command="_rSmScCQ8EeeKsvEah5BAoQ"/>
     <elements xsi:type="commands:Handler" xmi:id="_nSIiECUKEeeHw5lTgGMs1Q" elementId="eu.etaxonomy.taxeditor.handler.OpenImportPreferenceHandler" command="_fdEqUCUKEeeHw5lTgGMs1Q"/>
     <elements xsi:type="commands:Handler" xmi:id="_2fnUYCZ0EeeQLpuomSmVoQ" elementId="eu.etaxonomy.taxeditor.workbench.OpenPartHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.OpenPartHandler" command="_hMjgECZsEeer_rabtodzWA"/>
+    <elements xsi:type="commands:Handler" xmi:id="_dBGosFp0Eee4PsIXei-TMg" elementId="eu.etaxonomy.taxeditor.workbench.SaveHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.SaveHandler" command="_X-56IFp0Eee4PsIXei-TMg"/>
   </fragments>
 </fragment:ModelFragments>
index e450da4be8fc30538fdd1a66e722d8dd2f0fdfd2..b21d196893081156d7f62974462ac246be4753f0 100644 (file)
@@ -1,25 +1,39 @@
 
 package eu.etaxonomy.taxeditor.workbench;
 
-import javax.inject.Named;
+import java.util.Collections;
 
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.e4.core.commands.ECommandService;
+import org.eclipse.e4.core.commands.EHandlerService;
 import org.eclipse.e4.core.di.annotations.CanExecute;
 import org.eclipse.e4.core.di.annotations.Execute;
-import org.eclipse.e4.ui.model.application.ui.basic.MPart;
-import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.e4.ui.workbench.modeling.EPartService;
+import org.eclipse.ui.internal.e4.compatibility.CompatibilityPart;
 
 public class SaveHandler {
 
        @Execute
-       public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart, EPartService partService) {
-           partService.savePart(activePart, false);
+       public void execute(EPartService partService, ECommandService commandService, EHandlerService handlerService) {
+           partService.getDirtyParts().forEach(mPart ->
+           {
+               if(mPart.getObject() instanceof CompatibilityPart){
+                   //FIXME E4 remove when fully migrated
+                   Command command = commandService.getCommand("org.eclipse.ui.file.save");
+                ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(command, Collections.EMPTY_MAP);
+                   handlerService.executeHandler(parameterizedCommand);
+               }
+               else{
+                   partService.savePart(mPart, false);
+               }
+           });
        }
 
 
        @CanExecute
-       public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
-               return activePart.isDirty();
+       public boolean canExecute(EPartService partService) {
+           return !partService.getDirtyParts().isEmpty();
        }
 
 }
\ No newline at end of file