diff --git a/examples/org.eclipse.e4.ui.examples.e4editor/.classpath b/examples/org.eclipse.e4.ui.examples.e4editor/.classpath new file mode 100644 index 00000000000..0aa1aa099fb --- /dev/null +++ b/examples/org.eclipse.e4.ui.examples.e4editor/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/examples/org.eclipse.e4.ui.examples.e4editor/.project b/examples/org.eclipse.e4.ui.examples.e4editor/.project new file mode 100644 index 00000000000..3f4fe0a421d --- /dev/null +++ b/examples/org.eclipse.e4.ui.examples.e4editor/.project @@ -0,0 +1,28 @@ + + + org.eclipse.e4.ui.examples.e4editor + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/examples/org.eclipse.e4.ui.examples.e4editor/.settings/org.eclipse.core.resources.prefs b/examples/org.eclipse.e4.ui.examples.e4editor/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000000..4824b802631 --- /dev/null +++ b/examples/org.eclipse.e4.ui.examples.e4editor/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/examples/org.eclipse.e4.ui.examples.e4editor/.settings/org.eclipse.jdt.core.prefs b/examples/org.eclipse.e4.ui.examples.e4editor/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..a092867c450 --- /dev/null +++ b/examples/org.eclipse.e4.ui.examples.e4editor/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 +org.eclipse.jdt.core.compiler.compliance=21 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=21 diff --git a/examples/org.eclipse.e4.ui.examples.e4editor/META-INF/MANIFEST.MF b/examples/org.eclipse.e4.ui.examples.e4editor/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..26ed1576391 --- /dev/null +++ b/examples/org.eclipse.e4.ui.examples.e4editor/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: DummyEditor +Bundle-SymbolicName: org.eclipse.e4.ui.examples.e4editor;singleton:=true +Bundle-Version: 1.0.0.qualifier +Require-Bundle: org.eclipse.swt, + org.eclipse.jface, + org.eclipse.e4.core.contexts;bundle-version="1.13.0", + org.eclipse.e4.core.di;bundle-version="1.9.500", + org.eclipse.e4.ui.workbench;bundle-version="1.16.0", + org.eclipse.e4.ui.model.workbench;bundle-version="2.4.400", + jakarta.annotation-api, + org.eclipse.ui.workbench;bundle-version="3.133.100" +Automatic-Module-Name: org.eclipse.e4.ui.examples.dummyeditor +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-21 +Model-Fragment: fragment.e4xmi diff --git a/examples/org.eclipse.e4.ui.examples.e4editor/build.properties b/examples/org.eclipse.e4.ui.examples.e4editor/build.properties new file mode 100644 index 00000000000..8152e71a99e --- /dev/null +++ b/examples/org.eclipse.e4.ui.examples.e4editor/build.properties @@ -0,0 +1,5 @@ +bin.includes = META-INF/,\ + .,\ + fragment.e4xmi +source.. = src/ +output.. = bin/ diff --git a/examples/org.eclipse.e4.ui.examples.e4editor/fragment.e4xmi b/examples/org.eclipse.e4.ui.examples.e4editor/fragment.e4xmi new file mode 100644 index 00000000000..26ab1f6085b --- /dev/null +++ b/examples/org.eclipse.e4.ui.examples.e4editor/fragment.e4xmi @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + Editor + removeOnHide + + + diff --git a/examples/org.eclipse.e4.ui.examples.e4editor/src/org/eclipse/e4/ui/examples/e4editor/E4Editor.java b/examples/org.eclipse.e4.ui.examples.e4editor/src/org/eclipse/e4/ui/examples/e4editor/E4Editor.java new file mode 100644 index 00000000000..d31af60c744 --- /dev/null +++ b/examples/org.eclipse.e4.ui.examples.e4editor/src/org/eclipse/e4/ui/examples/e4editor/E4Editor.java @@ -0,0 +1,29 @@ +/******************************************************************************* +* Copyright (c) 2025 Feilim Breatnach and others. +* +* This program and the accompanying materials are made available under the +* terms of the Eclipse Public License 2.0 which accompanies this distribution, +* and is available at https://www.eclipse.org/legal/epl-2.0/ +* +* SPDX-License-Identifier: EPL-2.0 +* +* Contributors: Feilim Breatnach, Pilz Ireland +*******************************************************************************/ + +package org.eclipse.e4.ui.examples.e4editor; + +import jakarta.annotation.PostConstruct; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; + +public class E4Editor { + + @PostConstruct + public void postConstruct(Composite parent) { + Text label = new Text(parent, SWT.ITALIC); + label.setText("E4 Editor Content..."); + + } +} diff --git a/examples/org.eclipse.e4.ui.examples.e4editor/src/org/eclipse/e4/ui/examples/e4editor/OpenEditorHandler.java b/examples/org.eclipse.e4.ui.examples.e4editor/src/org/eclipse/e4/ui/examples/e4editor/OpenEditorHandler.java new file mode 100644 index 00000000000..a508c7b470d --- /dev/null +++ b/examples/org.eclipse.e4.ui.examples.e4editor/src/org/eclipse/e4/ui/examples/e4editor/OpenEditorHandler.java @@ -0,0 +1,78 @@ +/******************************************************************************* +* Copyright (c) 2025 Feilim Breatnach and others. +* +* This program and the accompanying materials are made available under the +* terms of the Eclipse Public License 2.0 which accompanies this distribution, +* and is available at https://www.eclipse.org/legal/epl-2.0/ +* +* SPDX-License-Identifier: EPL-2.0 +* +* Contributors: Feilim Breatnach, Pilz Ireland +*******************************************************************************/ + +package org.eclipse.e4.ui.examples.e4editor; + +import java.util.List; +import java.util.Optional; +import java.util.function.Predicate; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.ui.advanced.MArea; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer; +import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement; +import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; +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; + +public class OpenEditorHandler { + + public static final String DUMMY_EDITOR_DESCRIPTOR_ID = "org.eclipse.e4.ui.examples.e4editor.partdescriptor.e4editor"; + + @Execute + public void execute(EModelService modelService, MApplication application, EPartService partService) { + Predicate isEditorAlreadyOpenFilter = part -> DUMMY_EDITOR_DESCRIPTOR_ID.equals(part.getElementId()); + Optional alreadyOpenMatchingPart = partService.getParts().stream().filter(isEditorAlreadyOpenFilter) + .findFirst(); + + MPart dummyPart = alreadyOpenMatchingPart.orElse(partService.createPart(DUMMY_EDITOR_DESCRIPTOR_ID)); + if (alreadyOpenMatchingPart.isEmpty()) { + dummyPart = partService.createPart(DUMMY_EDITOR_DESCRIPTOR_ID); + + // not entirely necessary: but for consistency let's place our dummy editor + // where editor instances appear + Optional primaryDataStack = findPrimaryConfiguationAreaPartStack(application, modelService); + if (primaryDataStack.isPresent()) { + primaryDataStack.get().getChildren().add(dummyPart); + } + } else { + dummyPart = alreadyOpenMatchingPart.get(); + } + + partService.showPart(DUMMY_EDITOR_DESCRIPTOR_ID, PartState.ACTIVATE); + partService.bringToTop(dummyPart); + } + + private Optional findPrimaryConfiguationAreaPartStack(MApplication application, + EModelService modelService) { + // find the part stack from the application model which represents the area + // where our main 'editors' appear, ie. the main workspace area + List areaCandidates = modelService.findElements(application, org.eclipse.ui.IPageLayout.ID_EDITOR_AREA, + MArea.class, null, EModelService.IN_SHARED_ELEMENTS); + if (areaCandidates.size() == 1) { + MArea primaryArea = areaCandidates.get(0); + for (MPartSashContainerElement element : primaryArea.getChildren()) { + if (element instanceof MPartStack) { + return Optional.of((MPartStack) element); + } else if (element instanceof MPartSashContainer) { + return ((MPartSashContainer) element).getChildren().stream().filter(c -> c instanceof MPartStack) + .map(c -> (MPartStack) c).findFirst(); + } + } + } + + return Optional.empty(); + } +} \ No newline at end of file