Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/org.eclipse.e4.ui.examples.e4editor/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
28 changes: 28 additions & 0 deletions examples/org.eclipse.e4.ui.examples.e4editor/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.e4.ui.examples.e4editor</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions examples/org.eclipse.e4.ui.examples.e4editor/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions examples/org.eclipse.e4.ui.examples.e4editor/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bin.includes = META-INF/,\
.,\
fragment.e4xmi
source.. = src/
output.. = bin/
20 changes: 20 additions & 0 deletions examples/org.eclipse.e4.ui.examples.e4editor/fragment.e4xmi
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="ASCII"?>
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/descriptor/basic" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_6pcn8N7gEe-4ibwCH2r47g">
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_Bzi3IN7hEe-4ibwCH2r47g" featurename="menuContributions" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="menu:MenuContribution" xmi:id="_JtwUoN7hEe-4ibwCH2r47g" elementId="org.eclipse.e4.ui.examples.e4editor.menucontribution.0" positionInParent="after=additions" parentId="window">
<children xsi:type="menu:HandledMenuItem" xmi:id="_XMBQkN7hEe-4ibwCH2r47g" elementId="org.eclipse.e4.ui.examples.e4editor.handledmenuitem.opene4editor" label="Open E4 Editor" command="_e-OBkN7hEe-4ibwCH2r47g"/>
</elements>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_c1D8sN7hEe-4ibwCH2r47g" featurename="commands" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Command" xmi:id="_e-OBkN7hEe-4ibwCH2r47g" elementId="org.eclipse.e4.ui.examples.e4editor.command.opene4editor" commandName="Open E4 Editor"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="__zpxEN7iEe-4ibwCH2r47g" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Handler" xmi:id="_DRaRYN7jEe-4ibwCH2r47g" elementId="org.eclipse.e4.ui.examples.e4editor.handler.0" contributionURI="bundleclass://org.eclipse.e4.ui.examples.e4editor/org.eclipse.e4.ui.examples.e4editor.OpenEditorHandler" command="_e-OBkN7hEe-4ibwCH2r47g"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_WJS9YN7jEe-4ibwCH2r47g" featurename="descriptors" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="basic:PartDescriptor" xmi:id="_YIdYwN7jEe-4ibwCH2r47g" elementId="org.eclipse.e4.ui.examples.e4editor.partdescriptor.e4editor" label="E4 Editor" closeable="true" contributionURI="bundleclass://org.eclipse.e4.ui.examples.e4editor/org.eclipse.e4.ui.examples.e4editor.E4Editor">
<tags>Editor</tags>
<tags>removeOnHide</tags>
</elements>
</fragments>
</fragment:ModelFragments>
Original file line number Diff line number Diff line change
@@ -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...");

}
}
Original file line number Diff line number Diff line change
@@ -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<MPart> isEditorAlreadyOpenFilter = part -> DUMMY_EDITOR_DESCRIPTOR_ID.equals(part.getElementId());
Optional<MPart> 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<MPartStack> 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<MPartStack> 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<MArea> 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();
}
}
Loading