Author: scabanovich
Date: 2012-10-04 20:33:16 -0400 (Thu, 04 Oct 2012)
New Revision: 44323
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/wizard/service/RegisterAsServiceDialog.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/wizard/service/RegisterAsServiceHandler.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/wizard/service/RegisterServiceUtil.java
Log:
JBIDE-12793
https://issues.jboss.org/browse/JBIDE-12793
Code modified to simplify dialog testing.
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/wizard/service/RegisterAsServiceDialog.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/wizard/service/RegisterAsServiceDialog.java 2012-10-04
23:13:19 UTC (rev 44322)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/wizard/service/RegisterAsServiceDialog.java 2012-10-05
00:33:16 UTC (rev 44323)
@@ -3,8 +3,10 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.TreeMap;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.Flags;
@@ -23,6 +25,8 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.jboss.tools.common.java.IParametedType;
+import org.jboss.tools.common.java.ParametedType;
+import org.jboss.tools.common.java.ParametedTypeFactory;
import org.jboss.tools.common.ui.CommonUIMessages;
import org.jboss.tools.common.ui.CommonUIPlugin;
import org.jboss.tools.common.ui.widget.editor.IFieldEditor;
@@ -34,10 +38,11 @@
IFieldEditor serviceTypeSelector;
String result;
- public RegisterAsServiceDialog(Shell parentShell, IType type, Map<String,
IParametedType> types) {
+ public RegisterAsServiceDialog(Shell parentShell, IType type) {
super(parentShell);
this.type = type;
- this.types = types;
+ initTypes();
+
setShellStyle(getShellStyle() | SWT.RESIZE);
List<String> serviceTypeNames = new ArrayList<String>(types.keySet());
String defaultValue = serviceTypeNames.isEmpty() ? "" :
serviceTypeNames.get(0);
@@ -45,6 +50,21 @@
CommonUIMessages.REGISTER_AS_SERVICE_TYPE_LABEL, serviceTypeNames, defaultValue);
}
+ void initTypes() {
+ ParametedType parametedType = new ParametedTypeFactory().newParametedType(type);
+ Collection<IParametedType> ts = parametedType.getAllTypes();
+ Map<String, IParametedType> types = new TreeMap<String,
IParametedType>();
+ for (IParametedType t: ts) {
+ if(t.getType() != null) {
+ String q = t.getType().getFullyQualifiedName();
+ types.put(q, t);
+ }
+ }
+ types.remove("java.lang.Object"); //$NON-NLS-1$
+ types.remove(type.getFullyQualifiedName());
+ this.types = types;
+ }
+
private final int DIALOG_WIDTH = 400;
private final int DIALOG_HEIGHT = 60;
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/wizard/service/RegisterAsServiceHandler.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/wizard/service/RegisterAsServiceHandler.java 2012-10-04
23:13:19 UTC (rev 44322)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/wizard/service/RegisterAsServiceHandler.java 2012-10-05
00:33:16 UTC (rev 44323)
@@ -10,14 +10,9 @@
******************************************************************************/
package org.jboss.tools.common.ui.wizard.service;
-import java.util.Collection;
-import java.util.Map;
-import java.util.TreeMap;
-
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.expressions.IEvaluationContext;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.ICompilationUnit;
@@ -25,11 +20,9 @@
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
-import org.jboss.tools.common.java.IParametedType;
-import org.jboss.tools.common.java.ParametedType;
-import org.jboss.tools.common.java.ParametedTypeFactory;
import org.jboss.tools.common.ui.CommonUIPlugin;
/**
@@ -47,6 +40,14 @@
setBaseEnabled(computeEnabled(evaluationContext));
}
+ @Override
+ public Object execute(ExecutionEvent event) throws
org.eclipse.core.commands.ExecutionException {
+ ISelection selection =
HandlerUtil.getActiveWorkbenchWindow(event).getSelectionService().getSelection();
+ Shell shell = HandlerUtil.getActiveShell(event);
+ invokeWizard(selection, shell);
+ return null;
+ }
+
private boolean computeEnabled(Object evaluationContext) {
if(evaluationContext instanceof IEvaluationContext) {
IEvaluationContext c = (IEvaluationContext)evaluationContext;
@@ -61,7 +62,7 @@
* @param selection
* @return
*/
- private IType getSelectedType(ISelection selection) {
+ public static IType getSelectedType(ISelection selection) {
if(selection != null && !selection.isEmpty() && (selection instanceof
IStructuredSelection)) {
for (Object selected: ((IStructuredSelection)selection).toList()) {
try {
@@ -86,44 +87,22 @@
return null;
}
- private boolean accept(IType type) throws CoreException {
+ private static boolean accept(IType type) throws CoreException {
return !type.isInterface() && !type.isAnnotation() &&
!Flags.isAbstract(type.getFlags());
}
- @Override
- public Object execute(ExecutionEvent event) throws
org.eclipse.core.commands.ExecutionException {
- ISelection selection =
HandlerUtil.getActiveWorkbenchWindow(event).getSelectionService().getSelection();
+ public static void invokeWizard(ISelection selection, Shell shell) {
IType type = getSelectedType(selection);
if(type == null) {
- return null;
+ return;
}
+ RegisterAsServiceDialog dialog = new RegisterAsServiceDialog(shell, type);
try {
- ParametedType parametedType = new ParametedTypeFactory().newParametedType(type);
- Collection<IParametedType> ts = parametedType.getAllTypes();
- Map<String, IParametedType> types = new TreeMap<String,
IParametedType>();
- for (IParametedType t: ts) {
- if(t.getType() != null) {
- String q = t.getType().getFullyQualifiedName();
- types.put(q, t);
- }
+ if(dialog.open() == IDialogConstants.OK_ID) {
+ RegisterServiceUtil.registerService(type, dialog.getResult());
}
- types.remove("java.lang.Object"); //$NON-NLS-1$
- types.remove(type.getFullyQualifiedName());
-
- RegisterAsServiceDialog dialog = new
RegisterAsServiceDialog(HandlerUtil.getActiveShell(event), type, types);
- dialog.create();
-
- int i = dialog.open();
- if(i == IDialogConstants.OK_ID) {
- IProject project = type.getJavaProject().getProject();
- String typeName = type.getFullyQualifiedName();
- String serviceType = dialog.getResult();
- RegisterServiceUtil.registerService(project, typeName, serviceType);
- }
} catch (CoreException e) {
CommonUIPlugin.getDefault().logError(e);
}
- return null;
}
-
}
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/wizard/service/RegisterServiceUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/wizard/service/RegisterServiceUtil.java 2012-10-04
23:13:19 UTC (rev 44322)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/wizard/service/RegisterServiceUtil.java 2012-10-05
00:33:16 UTC (rev 44323)
@@ -20,6 +20,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IType;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.ui.CommonUIPlugin;
import org.jboss.tools.common.util.FileUtil;
@@ -113,6 +114,12 @@
}
}
+ public static void registerService(IType type, String serviceType) throws CoreException
{
+ IProject project = type.getJavaProject().getProject();
+ String typeName = type.getFullyQualifiedName();
+ registerService(project, typeName, serviceType);
+ }
+
/**
* Returns the first existing 'META-INF/services' folder in a Java source
folder,
* or newly created 'META-INF/services' folder in an existing Java source folder
if 'create' is set to true,