import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.commands.MCommand;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.advanced.MArea;
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
import org.simantics.db.Resource;
import org.simantics.utils.datastructures.ArrayMap;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
/**
* @author Tuukka Lehtonen
public static MPart getMPartById(String partId) {
IEclipseContext context = PlatformUI.getWorkbench().getService(IEclipseContext.class);
EPartService partService = context.get(EPartService.class);
- return partService.findPart(partId);
+ MPart part = partService.findPart(partId);
+ if (part == null)
+ part = partService.createPart(partId);
+ return part;
+ }
+
+ public static MCommand getMCommandById(String id) {
+ IEclipseContext context = PlatformUI.getWorkbench().getService(IEclipseContext.class);
+ MApplication application = context.get(MApplication.class);
+ for (MCommand command : application.getCommands()) {
+ if (id.equals(command.getElementId())) {
+ return command;
+ }
+ }
+ return null;
}
+ @SuppressWarnings("restriction")
+ public static IEditorPart getActiveIEditorPart(MPart mActiveEditorPart) {
+ // TODO: Fix this when we get rid of CompatibilityEditors
+ IEditorPart activeEditor = null;
+ if (mActiveEditorPart != null) {
+ Object editor = mActiveEditorPart.getObject();
+ if (editor instanceof CompatibilityEditor) {
+ CompatibilityEditor compEditor = (CompatibilityEditor) editor;
+ activeEditor = compEditor.getEditor();
+ } else {
+ // TODO: This is not good practice with E4 but an OK fallback for now
+ activeEditor = WorkbenchUtils.getActiveEditor();
+ }
+ }
+ return activeEditor;
+ }
}