aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Weise2014-02-06 12:40:11 (EST)
committerKonstantin Komissarchik2014-02-07 18:08:15 (EST)
commitc63a3e17521fbb8d0f239399f77307a0a22bd039 (patch)
treea57a7639facbaa83ae3e327416bda59b77283493
parenta53b9179a59cd3c0d5e5360995ebd2252b815991 (diff)
downloadorg.eclipse.sapphire-c63a3e17521fbb8d0f239399f77307a0a22bd039.zip
org.eclipse.sapphire-c63a3e17521fbb8d0f239399f77307a0a22bd039.tar.gz
org.eclipse.sapphire-c63a3e17521fbb8d0f239399f77307a0a22bd039.tar.bz2
Enhancement : Browse support for Java packages
Browse support is needed for value properties of JavaPackageName type. Bugzilla: https://bugs.eclipse.org/bugs/show_bug.cgi?id=427447 Signed-off-by: Andreas Weise <andreas.weise@agito-it.de>
-rw-r--r--plugins/org.eclipse.sapphire.java.jdt.ui/META-INF/sapphire-extension.xml10
-rw-r--r--plugins/org.eclipse.sapphire.java.jdt.ui/src/org/eclipse/sapphire/java/jdt/ui/internal/JavaPackageBrowseActionHandler.java93
2 files changed, 102 insertions, 1 deletions
diff --git a/plugins/org.eclipse.sapphire.java.jdt.ui/META-INF/sapphire-extension.xml b/plugins/org.eclipse.sapphire.java.jdt.ui/META-INF/sapphire-extension.xml
index f3cbeb1..ca7a9ff 100644
--- a/plugins/org.eclipse.sapphire.java.jdt.ui/META-INF/sapphire-extension.xml
+++ b/plugins/org.eclipse.sapphire.java.jdt.ui/META-INF/sapphire-extension.xml
@@ -2,7 +2,7 @@
<!--
******************************************************************************
- * Copyright (c) 2014 Oracle
+ * Copyright (c) 2014 Oracle and agito
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,6 +10,7 @@
*
* Contributors:
* Konstantin Komissarchik - initial implementation and ongoing maintenance
+ * Andreas Weise - [427447] Browse support for Java packages
******************************************************************************
-->
@@ -21,6 +22,13 @@
<description>Opens a browse dialog listing applicable Java types. Activates if the property is a reference value property from JavaTypeName to JavaType.</description>
<condition>org.eclipse.sapphire.java.jdt.ui.internal.JavaTypeBrowseActionHandler$Condition</condition>
</action-handler>
+ <action-handler>
+ <action>Sapphire.Browse</action>
+ <impl>org.eclipse.sapphire.java.jdt.ui.internal.JavaPackageBrowseActionHandler</impl>
+ <id>Sapphire.Browse.Java.Package</id>
+ <description>Opens a browse dialog listing applicable Java packages of the current project. Activates if the property is a value property and of type JavaPackageName.</description>
+ <condition>org.eclipse.sapphire.java.jdt.ui.internal.JavaPackageBrowseActionHandler$Condition</condition>
+ </action-handler>
<action-handler>
<action>Sapphire.Jump</action>
<impl>org.eclipse.sapphire.java.jdt.ui.internal.JavaTypeJumpActionHandler</impl>
diff --git a/plugins/org.eclipse.sapphire.java.jdt.ui/src/org/eclipse/sapphire/java/jdt/ui/internal/JavaPackageBrowseActionHandler.java b/plugins/org.eclipse.sapphire.java.jdt.ui/src/org/eclipse/sapphire/java/jdt/ui/internal/JavaPackageBrowseActionHandler.java
new file mode 100644
index 0000000..189d0aa
--- /dev/null
+++ b/plugins/org.eclipse.sapphire.java.jdt.ui/src/org/eclipse/sapphire/java/jdt/ui/internal/JavaPackageBrowseActionHandler.java
@@ -0,0 +1,93 @@
+/******************************************************************************
+ * Copyright (c) 2014 Oracle, Liferay and agito
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andreas Weise - initial implementation and ongoing maintenance
+ ******************************************************************************/
+
+package org.eclipse.sapphire.java.jdt.ui.internal;
+
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.sapphire.LocalizableText;
+import org.eclipse.sapphire.LoggingService;
+import org.eclipse.sapphire.Property;
+import org.eclipse.sapphire.Sapphire;
+import org.eclipse.sapphire.Text;
+import org.eclipse.sapphire.Value;
+import org.eclipse.sapphire.java.JavaPackageName;
+import org.eclipse.sapphire.modeling.CapitalizationType;
+import org.eclipse.sapphire.ui.Presentation;
+import org.eclipse.sapphire.ui.SapphireAction;
+import org.eclipse.sapphire.ui.def.ActionHandlerDef;
+import org.eclipse.sapphire.ui.forms.BrowseActionHandler;
+import org.eclipse.sapphire.ui.forms.PropertyEditorCondition;
+import org.eclipse.sapphire.ui.forms.PropertyEditorPart;
+import org.eclipse.sapphire.ui.forms.swt.FormComponentPresentation;
+import org.eclipse.ui.dialogs.SelectionDialog;
+
+/**
+ * @author <a href="mailto:andreas.weise@agito-it.de">Andreas Weise</a>
+ */
+
+public final class JavaPackageBrowseActionHandler extends BrowseActionHandler {
+
+ @Text("Select ")
+ private static LocalizableText select;
+
+ static {
+ LocalizableText.init(JavaPackageBrowseActionHandler.class);
+ }
+
+ public static final String ID = "Sapphire.Browse.Java.Package";
+
+ @Override
+ public void init(final SapphireAction action, final ActionHandlerDef def) {
+ super.init(action, def);
+
+ setId(ID);
+ }
+
+ @Override
+ public String browse(final Presentation context) {
+ final Property property = property();
+
+ final IJavaProject project = property.element().adapt(IJavaProject.class);
+
+ try {
+ final SelectionDialog dlg = JavaUI.createPackageDialog(((FormComponentPresentation) context).shell(),
+ project, 0, null);
+
+ final String title = property.definition().getLabel(true, CapitalizationType.TITLE_STYLE, false);
+ dlg.setTitle(select + title);
+
+ if (dlg.open() == SelectionDialog.OK) {
+ Object results[] = dlg.getResult();
+ assert results != null && results.length == 1;
+ if (results[0] instanceof IPackageFragment) {
+ return ((IPackageFragment) results[0]).getElementName();
+ }
+ }
+ } catch (JavaModelException e) {
+ Sapphire.service(LoggingService.class).log(e);
+ }
+
+ return null;
+ }
+
+ public static final class Condition extends PropertyEditorCondition {
+ @Override
+ protected boolean evaluate(final PropertyEditorPart part) {
+ final Property property = part.property();
+
+ return (property instanceof Value && property.definition().isOfType(JavaPackageName.class));
+ }
+ }
+
+} \ No newline at end of file