1 package org.argeo.cms.e4.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.basic.MPart; 6 import org.eclipse.e4.ui.workbench.modeling.EPartService; 7 8 public class CloseAllParts { 9 10 @Execute 11 void execute(EPartService partService) { 12 for (MPart part : partService.getParts()) { 13 if (part.isCloseable()) { 14 if (part.isDirty()) { 15 if (partService.savePart(part, true)) { 16 partService.hidePart(part, true); 17 } 18 } else { 19 partService.hidePart(part, true); 20 } 21 } 22 } 23 } 24 25 @CanExecute 26 boolean canExecute(EPartService partService) { 27 boolean atLeastOnePart = false; 28 for (MPart part : partService.getParts()) { 29 if (part.isVisible() && part.isCloseable()) { 30 atLeastOnePart = true; 31 break; 32 } 33 } 34 return atLeastOnePart; 35 } 36 37 }