From 3fb5dd0212148b3cd84dda23d15e2c1b442f71e5 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Fri, 24 Oct 2025 14:00:55 +0200 Subject: [PATCH 1/3] Add SearchToolControl to Application.e4xmi menu --- com.vogella.tasks.ui/Application.e4xmi | 1 + 1 file changed, 1 insertion(+) diff --git a/com.vogella.tasks.ui/Application.e4xmi b/com.vogella.tasks.ui/Application.e4xmi index 9075de41..d94d2507 100644 --- a/com.vogella.tasks.ui/Application.e4xmi +++ b/com.vogella.tasks.ui/Application.e4xmi @@ -89,6 +89,7 @@ + From 80bde55d4b505b1f100226a939bc979174cdebc5 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Tue, 11 Nov 2025 12:02:13 +0100 Subject: [PATCH 2/3] Updating example --- .mvn/extensions.xml | 2 +- .../META-INF/MANIFEST.MF | 7 +- .../build.properties | 3 +- com.vogella.tasks.ui.contribute/plugin.xml | 17 ++++ .../ui/contribute/dialogs/ExitDialog.java | 29 +++++++ .../handlers/ExitHandlerWithCheck.java | 20 +++++ .../contribute/processors/MenuProcessor.java | 49 +++++++++++ com.vogella.tasks.ui/Application.e4xmi | 11 ++- com.vogella.tasks.ui/META-INF/MANIFEST.MF | 3 +- .../tasks/ui/parts/PlaygroundPart.java | 82 +++++++++++-------- .../ui/toolcontrols/SearchToolControl.java | 12 ++- pom.xml | 7 +- target-platform/target-platform.target | 6 +- 13 files changed, 189 insertions(+), 59 deletions(-) create mode 100644 com.vogella.tasks.ui.contribute/plugin.xml create mode 100644 com.vogella.tasks.ui.contribute/src/com/vogella/tasks/ui/contribute/dialogs/ExitDialog.java create mode 100644 com.vogella.tasks.ui.contribute/src/com/vogella/tasks/ui/contribute/handlers/ExitHandlerWithCheck.java create mode 100644 com.vogella.tasks.ui.contribute/src/com/vogella/tasks/ui/contribute/processors/MenuProcessor.java diff --git a/.mvn/extensions.xml b/.mvn/extensions.xml index 1512cb63..ea8b3ea1 100644 --- a/.mvn/extensions.xml +++ b/.mvn/extensions.xml @@ -2,6 +2,6 @@ org.eclipse.tycho tycho-build - 4.0.10 + 5.0.0 \ No newline at end of file diff --git a/com.vogella.tasks.ui.contribute/META-INF/MANIFEST.MF b/com.vogella.tasks.ui.contribute/META-INF/MANIFEST.MF index 81f61bdc..e9412678 100644 --- a/com.vogella.tasks.ui.contribute/META-INF/MANIFEST.MF +++ b/com.vogella.tasks.ui.contribute/META-INF/MANIFEST.MF @@ -1,15 +1,18 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Contribute -Bundle-SymbolicName: com.vogella.tasks.ui.contribute +Bundle-SymbolicName: com.vogella.tasks.ui.contribute;singleton:=true Bundle-Version: 1.0.0.qualifier +Import-Package: jakarta.inject;version="2.0.1", + org.eclipse.e4.ui.services Bundle-Vendor: VOGELLA Require-Bundle: org.eclipse.core.runtime, org.eclipse.jface, org.eclipse.e4.core.di, org.eclipse.e4.ui.workbench, org.eclipse.e4.ui.di, - org.eclipse.e4.ui.model.workbench + org.eclipse.e4.ui.model.workbench, + org.eclipse.e4.core.contexts;bundle-version="1.13.200" Bundle-RequiredExecutionEnvironment: JavaSE-21 Model-Fragment: fragment.e4xmi Automatic-Module-Name: com.vogella.tasks.ui.contribute diff --git a/com.vogella.tasks.ui.contribute/build.properties b/com.vogella.tasks.ui.contribute/build.properties index 3bf71187..9a7cc755 100644 --- a/com.vogella.tasks.ui.contribute/build.properties +++ b/com.vogella.tasks.ui.contribute/build.properties @@ -1,5 +1,6 @@ bin.includes = META-INF/,\ .,\ - fragment.e4xmi + fragment.e4xmi,\ + plugin.xml source.. = src/ output.. = bin/ diff --git a/com.vogella.tasks.ui.contribute/plugin.xml b/com.vogella.tasks.ui.contribute/plugin.xml new file mode 100644 index 00000000..1854ec43 --- /dev/null +++ b/com.vogella.tasks.ui.contribute/plugin.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/com.vogella.tasks.ui.contribute/src/com/vogella/tasks/ui/contribute/dialogs/ExitDialog.java b/com.vogella.tasks.ui.contribute/src/com/vogella/tasks/ui/contribute/dialogs/ExitDialog.java new file mode 100644 index 00000000..3fcb0cfc --- /dev/null +++ b/com.vogella.tasks.ui.contribute/src/com/vogella/tasks/ui/contribute/dialogs/ExitDialog.java @@ -0,0 +1,29 @@ +package com.vogella.tasks.ui.contribute.dialogs; + +import jakarta.inject.Inject; +import jakarta.inject.Named; + +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +public class ExitDialog extends Dialog { + @Inject + public ExitDialog(@Named(IServiceConstants. + ACTIVE_SHELL) Shell shell) { + super(shell); + } + + @Override + protected Control createDialogArea(Composite parent) { + Label label = new Label(parent, SWT.NONE); + label.setText("Closing this application may result in data loss. " + + "Are you sure you want that?"); + return parent; + } + +} diff --git a/com.vogella.tasks.ui.contribute/src/com/vogella/tasks/ui/contribute/handlers/ExitHandlerWithCheck.java b/com.vogella.tasks.ui.contribute/src/com/vogella/tasks/ui/contribute/handlers/ExitHandlerWithCheck.java new file mode 100644 index 00000000..06a1bbe9 --- /dev/null +++ b/com.vogella.tasks.ui.contribute/src/com/vogella/tasks/ui/contribute/handlers/ExitHandlerWithCheck.java @@ -0,0 +1,20 @@ +package com.vogella.tasks.ui.contribute.handlers; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.workbench.IWorkbench; +import org.eclipse.jface.window.Window; + +import com.vogella.tasks.ui.contribute.dialogs.ExitDialog; + +public class ExitHandlerWithCheck { + @Execute + public void execute(IEclipseContext context, IWorkbench workbench) { + ExitDialog dialog = ContextInjectionFactory. + make(ExitDialog.class, context); + if (dialog.open() == Window.OK) { + workbench.close(); + } + } +} diff --git a/com.vogella.tasks.ui.contribute/src/com/vogella/tasks/ui/contribute/processors/MenuProcessor.java b/com.vogella.tasks.ui.contribute/src/com/vogella/tasks/ui/contribute/processors/MenuProcessor.java new file mode 100644 index 00000000..8964ae9a --- /dev/null +++ b/com.vogella.tasks.ui.contribute/src/com/vogella/tasks/ui/contribute/processors/MenuProcessor.java @@ -0,0 +1,49 @@ +package com.vogella.tasks.ui.contribute.processors; + +import java.util.ArrayList; +import java.util.List; + +import jakarta.inject.Inject; +import jakarta.inject.Named; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem; +import org.eclipse.e4.ui.model.application.ui.menu.MMenu; +import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; +import org.eclipse.e4.ui.workbench.modeling.EModelService; + +import com.vogella.tasks.ui.contribute.handlers.ExitHandlerWithCheck; + +public class MenuProcessor { + + // the menu is injected based on the parameter + // defined in the extension point + @Inject + @Named("org.eclipse.ui.file.menu") + private MMenu menu; + + @Execute + public void execute(EModelService modelService) { + // remove the old exit menu entry + if (!menu.getChildren().isEmpty()) { + List list = new ArrayList<>(); + for (MMenuElement element : menu.getChildren()) { + // use ID instead of label as label is later translated + if (element.getElementId() != null) { + if (element.getElementId().contains("exit")) { + list.add(element); + } + } + } + menu.getChildren().removeAll(list); + } + + // now add a new menu entry + MDirectMenuItem menuItem = modelService.createModelElement(MDirectMenuItem.class); + menuItem.setLabel("Another Exit"); + menuItem.setContributionURI("bundleclass://" + + "com.vogella.tasks.ui.contribute/" + + ExitHandlerWithCheck.class.getName()); + menu.getChildren().add(menuItem); + } +} diff --git a/com.vogella.tasks.ui/Application.e4xmi b/com.vogella.tasks.ui/Application.e4xmi index d94d2507..bfbace04 100644 --- a/com.vogella.tasks.ui/Application.e4xmi +++ b/com.vogella.tasks.ui/Application.e4xmi @@ -45,17 +45,12 @@ - + - - - - - @@ -77,6 +72,9 @@ + + + @@ -126,6 +124,7 @@ + diff --git a/com.vogella.tasks.ui/META-INF/MANIFEST.MF b/com.vogella.tasks.ui/META-INF/MANIFEST.MF index 79d737da..940ea72b 100644 --- a/com.vogella.tasks.ui/META-INF/MANIFEST.MF +++ b/com.vogella.tasks.ui/META-INF/MANIFEST.MF @@ -22,7 +22,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.18.0", com.vogella.tasks.events;bundle-version="1.0.0", org.eclipse.swt, org.eclipse.jface, - org.osgi.service.event + org.osgi.service.event, + org.eclipse.nebula.widgets.chips;bundle-version="2.0.0" Bundle-RequiredExecutionEnvironment: JavaSE-21 Automatic-Module-Name: com.vogella.tasks.ui Import-Package: com.vogella.swt.widgets, diff --git a/com.vogella.tasks.ui/src/com/vogella/tasks/ui/parts/PlaygroundPart.java b/com.vogella.tasks.ui/src/com/vogella/tasks/ui/parts/PlaygroundPart.java index ed01003d..059cf9e8 100644 --- a/com.vogella.tasks.ui/src/com/vogella/tasks/ui/parts/PlaygroundPart.java +++ b/com.vogella.tasks.ui/src/com/vogella/tasks/ui/parts/PlaygroundPart.java @@ -1,58 +1,68 @@ package com.vogella.tasks.ui.parts; -import org.eclipse.e4.core.di.annotations.Optional; -import org.eclipse.e4.core.di.extensions.EventTopic; -import org.eclipse.e4.ui.di.Persist; -import org.eclipse.e4.ui.model.application.ui.basic.MPart; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.resource.LocalResourceManager; -import org.eclipse.jface.resource.ResourceManager; +import static org.eclipse.jface.layout.GridDataFactory.fillDefaults; +import static org.eclipse.jface.widgets.WidgetFactory.button; +import static org.eclipse.jface.widgets.WidgetFactory.text; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +import org.eclipse.e4.ui.di.Focus; +import org.eclipse.jface.fieldassist.ContentProposalAdapter; +import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; +import org.eclipse.jface.fieldassist.TextContentAdapter; +import org.eclipse.nebula.widgets.chips.Chips; import org.eclipse.swt.SWT; import org.eclipse.swt.browser.Browser; -import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Text; -import com.vogella.imageloader.services.IBundleResourceLoader; - import jakarta.annotation.PostConstruct; -import jakarta.inject.Inject; public class PlaygroundPart { private Text text; private Browser browser; - private Text target; - - - @Inject - MPart part; - @Inject - IBundleResourceLoader loader; @PostConstruct public void createControls(Composite parent) { + parent.setLayout(new GridLayout(2, false)); + Chips chip1 = new Chips(parent, SWT.CLOSE); + chip1.setText("Example"); + chip1.setChipsBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED)); + text = text(SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL).message("Enter City") + .layoutData(fillDefaults().grab(true, false).create()).create(parent); + text.addSelectionListener(SelectionListener.widgetDefaultSelectedAdapter(e -> updateBrowser())); + + ContentProposalAdapter contentProposal = new ContentProposalAdapter(text, new TextContentAdapter(), + new SimpleContentProposalProvider("Hamburg", "New York", "New Delhi"), null, null); - Label label = new Label(parent, SWT.NONE); - - // the following code assumes that you have a vogella.png file - // in a folder called "images" in this plug-in - ResourceManager resourceManager = - new LocalResourceManager(JFaceResources.getResources(), label); - Image image = resourceManager. - create(loader.getImageDescriptor(this.getClass(), "images/sbahn.svg")); - label.setImage(image); - + contentProposal.setPopupSize(new Point(200, 100)); + contentProposal.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); + button(SWT.PUSH).text("Search").onSelect(e -> updateBrowser()).create(parent); + + browser = new Browser(parent, SWT.NONE); + browser.setLayoutData(fillDefaults().grab(true, true).span(2, 1).create()); } - @Persist - public void saveItReallyReally() { - // TODO really do the saving - part.setDirty(false); + private void updateBrowser() { + String city = text.getText(); + if (city.isEmpty()) { + return; + } + try { + browser.setUrl("https://www.google.com/maps/place/" + URLEncoder.encode(city, "UTF-8") + "/&output=embed"); + + } catch (UnsupportedEncodingException e1) { + e1.printStackTrace(); + } } - @Inject - public void getFromOSGi(@Optional @EventTopic("YOURKEY") String value) { - System.out.println(value); + @Focus + public void onFocus() { + text.setFocus(); } } \ No newline at end of file diff --git a/com.vogella.tasks.ui/src/com/vogella/tasks/ui/toolcontrols/SearchToolControl.java b/com.vogella.tasks.ui/src/com/vogella/tasks/ui/toolcontrols/SearchToolControl.java index 8188b1f0..d11ee3a6 100644 --- a/com.vogella.tasks.ui/src/com/vogella/tasks/ui/toolcontrols/SearchToolControl.java +++ b/com.vogella.tasks.ui/src/com/vogella/tasks/ui/toolcontrols/SearchToolControl.java @@ -1,17 +1,21 @@ package com.vogella.tasks.ui.toolcontrols; -import jakarta.annotation.PostConstruct; - +import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Text; +import jakarta.annotation.PostConstruct; + public class SearchToolControl { @PostConstruct public void createGui(Composite parent) { - Text text = new Text(parent, SWT.SEARCH | SWT.CANCEL | SWT.BORDER); + final Composite comp = new Composite(parent, SWT.NONE); + comp.setLayout(new GridLayout()); + Text text = new Text(comp, SWT.SEARCH | SWT.CANCEL | SWT.ICON_SEARCH | SWT.BORDER); text.setMessage("Search"); - + GridDataFactory.fillDefaults().hint(130, SWT.DEFAULT).applyTo(text); } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index d7e7db6f..23d24a6a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ pom - 4.0.10 + 5.0.0 UTF-8 21 21 @@ -121,9 +121,9 @@ com.vogella.tasks.ui.contribute com.vogella.eclipse.css com.vogella.tasks.product -<<<<<<< Upstream, based on origin/main + com.vogella.swt.widgets diff --git a/target-platform/target-platform.target b/target-platform/target-platform.target index 762730d3..4c0c879e 100644 --- a/target-platform/target-platform.target +++ b/target-platform/target-platform.target @@ -11,12 +11,10 @@ - From 9e136bfed60e77f72e2df586afed37d2d22bcd4f Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Tue, 11 Nov 2025 16:20:15 +0100 Subject: [PATCH 3/3] Dark theme enabled --- com.vogella.tasks.ui/plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.vogella.tasks.ui/plugin.xml b/com.vogella.tasks.ui/plugin.xml index a260032a..01e25a16 100644 --- a/com.vogella.tasks.ui/plugin.xml +++ b/com.vogella.tasks.ui/plugin.xml @@ -13,7 +13,7 @@ value="to-do">