[jbosstools-commits] JBoss Tools SVN: r43544 - in trunk: runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core and 9 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Mon Sep 10 03:43:30 EDT 2012
Author: rob.stryker at jboss.com
Date: 2012-09-10 03:43:29 -0400 (Mon, 10 Sep 2012)
New Revision: 43544
Added:
trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/IRuntimePathChangeListener.java
Removed:
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/IRuntimePathChangeListener.java
Modified:
trunk/as/plugins/org.jboss.tools.runtime.as.detector/src/org/jboss/tools/runtime/handlers/JBossASHandler.java
trunk/runtime-soa/tests/org.jboss.tools.runtime.soa.test/src/org/jboss/tools/runtime/test/RuntimeDetectionTest.java
trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/JBossRuntimeLocator.java
trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/RuntimePath.java
trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeInitializerUtil.java
trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeModelUtil.java
trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimePathPreferenceIO.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/JBossRuntimeStartup.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeCheckboxTreeViewer.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeScanner.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeUIActivator.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeWorkbenchUtils.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/EditRuntimePathDialog.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/SearchRuntimePathDialog.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/download/DownloadRuntimeDialog.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/download/DownloadRuntimes.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/preferences/RuntimePreferencePage.java
trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/dialog/preferences/RuntimeDetectionPreferencesDialog.java
trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionFrameworkTest.java
Log:
/JBIDE-12549 more fixes to api
Modified: trunk/as/plugins/org.jboss.tools.runtime.as.detector/src/org/jboss/tools/runtime/handlers/JBossASHandler.java
===================================================================
--- trunk/as/plugins/org.jboss.tools.runtime.as.detector/src/org/jboss/tools/runtime/handlers/JBossASHandler.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/as/plugins/org.jboss.tools.runtime.as.detector/src/org/jboss/tools/runtime/handlers/JBossASHandler.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -257,8 +257,6 @@
final File location = getLocation(runtimeDefinition);
File[] directories = runtimeDefinition.getLocation().listFiles(
new FileFilter() {
-
- @Override
public boolean accept(File file) {
if (!file.isDirectory() || file.equals(location)) {
return false;
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/JBossRuntimeLocator.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/JBossRuntimeLocator.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/JBossRuntimeLocator.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -73,15 +73,42 @@
}
- public void searchDirectory(File directory, List<RuntimeDefinition> runtimeCollector,
+ /**
+ * Allows all runtime detectors to search through a directory
+ * for their runtime types.
+ *
+ * @param directory
+ * @param runtimeCollector
+ * @param depth
+ * @param monitor
+ */
+ public void searchDirectory(File directory,
+ List<RuntimeDefinition> runtimeCollector,
int depth, IProgressMonitor monitor) {
+ Set<IRuntimeDetector> runtimeDetectors = RuntimeCoreActivator.getDefault().getRuntimeDetectors();
+ searchDirectory(directory, runtimeCollector, depth, runtimeDetectors, monitor);
+ }
+
+ /**
+ * Allows a given set or subset of runtime detectors
+ * the ability to search through a folder
+ *
+ * @param directory
+ * @param runtimeCollector
+ * @param depth
+ * @param runtimeDetectors
+ * @param monitor
+ */
+ public void searchDirectory(File directory,
+ List<RuntimeDefinition> runtimeCollector,
+ int depth, Set<IRuntimeDetector> runtimeDetectors, IProgressMonitor monitor) {
+
if (depth == 0 || monitor.isCanceled() || directory == null || !directory.isDirectory()) {
return;
}
monitor.setTaskName("Searching " + directory.getAbsolutePath());
- Set<IRuntimeDetector> runtimeDetectors = RuntimeCoreActivator.getDefault().getRuntimeDetectors();
for (IRuntimeDetector detector:runtimeDetectors) {
if (monitor.isCanceled()) {
return;
@@ -106,7 +133,7 @@
for (int i = 0; i < size; i++) {
if (monitor.isCanceled())
return;
- searchDirectory(files[i], runtimeCollector, depth - 1, monitor);
+ searchDirectory(files[i], runtimeCollector, depth - 1, runtimeDetectors, monitor);
}
}
}
Copied: trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/IRuntimePathChangeListener.java (from rev 43455, trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/IRuntimePathChangeListener.java)
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/IRuntimePathChangeListener.java (rev 0)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/IRuntimePathChangeListener.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -0,0 +1,7 @@
+package org.jboss.tools.runtime.core.model;
+
+public interface IRuntimePathChangeListener {
+
+ void changed();
+
+}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/RuntimePath.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/RuntimePath.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/RuntimePath.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -12,10 +12,9 @@
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
-import org.jboss.tools.runtime.core.model.RuntimeDefinition;
-
/**
* @author snjeza
*
@@ -50,10 +49,21 @@
this.scanOnEveryStartup = scanOnEveryStartup;
}
- public List<RuntimeDefinition> getRuntimeDefinitions() {
- return runtimeDefinitions;
+ public RuntimeDefinition[] getRuntimeDefinitions() {
+ return runtimeDefinitions.toArray(new RuntimeDefinition[runtimeDefinitions.size()]);
}
+ public void setRuntimeDefinitions(RuntimeDefinition[] defs2) {
+ ArrayList<RuntimeDefinition> defs = new ArrayList<RuntimeDefinition>();
+ defs.addAll(Arrays.asList(defs2));
+ runtimeDefinitions = defs;
+ }
+
+ public void addRuntimeDefinition(RuntimeDefinition def) {
+ if( !runtimeDefinitions.contains(def))
+ runtimeDefinitions.add(def);
+ }
+
@Override
public Object clone() throws CloneNotSupportedException {
RuntimePath runtimePath = new RuntimePath(path);
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeInitializerUtil.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeInitializerUtil.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeInitializerUtil.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -1,6 +1,8 @@
package org.jboss.tools.runtime.core.util;
import java.io.File;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -20,6 +22,13 @@
}
}
+ /**
+ * This is a long-running task which may involve bundle-loading.
+ * This should not be called from the UI thread directly unless
+ * proper safety is taken.
+ *
+ * @param runtimeDefinitions
+ */
public static void initializeRuntimes(List<RuntimeDefinition> runtimeDefinitions) {
Set<IRuntimeDetector> detectors = RuntimeCoreActivator.getDefault().getRuntimeDetectors();
for( IRuntimeDetector detector:detectors) {
@@ -29,22 +38,49 @@
}
}
+ /**
+ * This is a long-running task which may involve bundle-loading.
+ * This should not be called from the UI thread directly unless
+ * proper safety is taken.
+ * @param runtimePaths
+ * @param monitor
+ */
+ public static void createRuntimeDefinitions(RuntimePath[] runtimePaths, IProgressMonitor monitor) {
+ HashSet<RuntimePath> set = new HashSet<RuntimePath>(Arrays.asList(runtimePaths));
+ createRuntimeDefinitions(set, monitor);
+ }
+
+ /**
+ * This is a long-running task which may involve bundle-loading.
+ * This should not be called from the UI thread directly unless
+ * proper safety is taken.
+ * @param runtimePaths
+ * @param monitor
+ */
public static void createRuntimeDefinitions(Set<RuntimePath> runtimePaths, IProgressMonitor monitor) {
for (RuntimePath runtimePath : runtimePaths) {
- // TODO sub monitors
createRuntimeDefinitions(runtimePath, monitor);
}
}
+ /**
+ * This is a long-running task which may involve bundle-loading.
+ * This should not be called from the UI thread directly unless
+ * proper safety is taken.
+ * @param runtimePath
+ * @param monitor
+ * @return
+ */
public static List<RuntimeDefinition> createRuntimeDefinitions(RuntimePath runtimePath, IProgressMonitor monitor) {
JBossRuntimeLocator locator = new JBossRuntimeLocator();
List<RuntimeDefinition> runtimeDefinitions = locator
.searchForRuntimes(runtimePath.getPath(), monitor);
- runtimePath.getRuntimeDefinitions().clear();
for (RuntimeDefinition runtimeDefinition : runtimeDefinitions) {
runtimeDefinition.setRuntimePath(runtimePath);
}
- runtimePath.getRuntimeDefinitions().addAll(runtimeDefinitions);
+ RuntimeDefinition[] defs = runtimeDefinitions.toArray(
+ new RuntimeDefinition[runtimeDefinitions.size()]);
+ runtimePath.setRuntimeDefinitions(defs);
return runtimeDefinitions;
}
}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeModelUtil.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeModelUtil.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimeModelUtil.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -5,8 +5,11 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;
@@ -16,6 +19,7 @@
import org.jboss.tools.runtime.core.RuntimeCoreActivator;
import org.jboss.tools.runtime.core.model.IRuntimeDetector;
import org.jboss.tools.runtime.core.model.RuntimeDefinition;
+import org.jboss.tools.runtime.core.model.RuntimeModel;
import org.jboss.tools.runtime.core.model.RuntimePath;
public class RuntimeModelUtil {
@@ -85,7 +89,7 @@
return runtimePaths;
}
- public static void updateTimestamps(Set<RuntimePath> runtimePaths2) {
+ public static void updateTimestamps(RuntimePath[] runtimePaths2) {
for (RuntimePath runtimePath : runtimePaths2) {
String path = runtimePath.getPath();
if (path != null && !path.isEmpty()) {
@@ -134,4 +138,50 @@
return (created);
}
+ public static List<RuntimeDefinition> getRuntimeDefinitions(Set<RuntimePath> runtimePaths) {
+ RuntimePath[] paths = (RuntimePath[]) runtimePaths.toArray(new RuntimePath[runtimePaths.size()]);
+ return getRuntimeDefinitions(paths);
+ }
+
+ public static List<RuntimeDefinition> getRuntimeDefinitions(RuntimePath[] runtimePaths) {
+ ArrayList<RuntimeDefinition> runtimeDefinitions = new ArrayList<RuntimeDefinition>();
+ for (RuntimePath runtimePath:runtimePaths) {
+ runtimeDefinitions.addAll(Arrays.asList(runtimePath.getRuntimeDefinitions()));
+ }
+ return runtimeDefinitions;
+ }
+
+ public static List<RuntimeDefinition> getAllDefinitions(RuntimePath runtimePath) {
+ return getAllDefinitions(new RuntimePath[]{runtimePath});
+ }
+
+ public static List<RuntimeDefinition> getAllDefinitions(RuntimePath[] runtimePath) {
+ List<RuntimeDefinition> allDefinitions = new ArrayList<RuntimeDefinition>();
+ for( int i = 0; i < runtimePath.length; i++ ) {
+ allDefinitions.addAll(Arrays.asList(runtimePath[i].getRuntimeDefinitions()));
+ for (RuntimeDefinition runtimeDefinition : runtimePath[i].getRuntimeDefinitions()) {
+ allDefinitions.addAll(runtimeDefinition.getIncludedRuntimeDefinitions());
+ }
+ }
+ return allDefinitions;
+ }
+
+ public static boolean runtimeDefinitionsExists(RuntimeDefinition runtimeDefinition, RuntimeModel model) {
+ return runtimeDefinitionsExists(runtimeDefinition, model.getRuntimePaths());
+ }
+
+ public static boolean runtimeDefinitionsExists(RuntimeDefinition runtimeDefinition, RuntimePath[] paths) {
+ return runtimeDefinitionsExists(runtimeDefinition, getRuntimeDefinitions(paths));
+ }
+
+ public static boolean runtimeDefinitionsExists(RuntimeDefinition runtimeDefinition,
+ List<RuntimeDefinition> allRuntimeDefinitions) {
+ Iterator<RuntimeDefinition> it = allRuntimeDefinitions.iterator();
+ while(it.hasNext()) {
+ if( it.next().equals(runtimeDefinition))
+ return true;
+ }
+ return false;
+ }
+
}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimePathPreferenceIO.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimePathPreferenceIO.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/util/RuntimePathPreferenceIO.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -8,6 +8,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -47,9 +48,9 @@
runtimePathNode.putString(PATH, runtimePath.getPath());
runtimePathNode.putBoolean(SCAN_ON_EVERY_STAERTUP, runtimePath.isScanOnEveryStartup());
runtimePathNode.putString(TIMESTAMP, String.valueOf(runtimePath.getTimestamp()));
- IMemento serverDefinitionsNode = runtimePathNode.createChild(SERVER_DEFINITIONS);
- List<RuntimeDefinition> definitions = runtimePath.getRuntimeDefinitions();
- putDefinitions(serverDefinitionsNode, definitions);
+ IMemento runtimeDefinitionsNode = runtimePathNode.createChild(SERVER_DEFINITIONS);
+ RuntimeDefinition[] definitions = runtimePath.getRuntimeDefinitions();
+ putDefinitions(runtimeDefinitionsNode, definitions);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -71,7 +72,7 @@
}
private static void putDefinitions(IMemento runtimeDefintionsNode,
- List<RuntimeDefinition> definitions) {
+ RuntimeDefinition[] definitions) {
for (RuntimeDefinition runtimeDefinition:definitions) {
IMemento sdNode = runtimeDefintionsNode.createChild(SERVER_DEFINITION);
putRuntimeDefinition(runtimeDefinition, sdNode);
@@ -127,8 +128,8 @@
IMemento serverDefinitionsNode = node.getChild(SERVER_DEFINITIONS);
IMemento[] sdNodes = serverDefinitionsNode.getChildren(SERVER_DEFINITION);
for (IMemento sdNode:sdNodes) {
- RuntimeDefinition serverDefinition = createRuntimeDefinition(sdNode);
- serverDefinition.setRuntimePath(runtimePath);
+ RuntimeDefinition runtimeDefinition = createRuntimeDefinition(sdNode);
+ runtimeDefinition.setRuntimePath(runtimePath);
IMemento includedDefinition = sdNode.getChild(INCLUDED_DEFINITION);
if (includedDefinition != null) {
IMemento[] includedNodes = includedDefinition
@@ -136,12 +137,12 @@
for (IMemento includedNode : includedNodes) {
RuntimeDefinition included = createRuntimeDefinition(includedNode);
included.setRuntimePath(runtimePath);
- included.setParent(serverDefinition);
- serverDefinition.getIncludedRuntimeDefinitions().add(
+ included.setParent(runtimeDefinition);
+ runtimeDefinition.getIncludedRuntimeDefinitions().add(
included);
}
}
- runtimePath.getRuntimeDefinitions().add(serverDefinition);
+ runtimePath.addRuntimeDefinition(runtimeDefinition);
}
runtimePaths.add(runtimePath);
}
@@ -173,7 +174,7 @@
private static List<RuntimeDefinition> getAllRuntimeDefinitions(Set<RuntimePath> paths) {
List<RuntimeDefinition> defs = new ArrayList<RuntimeDefinition>();
for( Iterator<RuntimePath> i = paths.iterator(); i.hasNext(); ) {
- defs.addAll(i.next().getRuntimeDefinitions());
+ defs.addAll(Arrays.asList(i.next().getRuntimeDefinitions()));
}
return defs;
}
Deleted: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/IRuntimePathChangeListener.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/IRuntimePathChangeListener.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/IRuntimePathChangeListener.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -1,7 +0,0 @@
-package org.jboss.tools.runtime.ui;
-
-public interface IRuntimePathChangeListener {
-
- void changed();
-
-}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/JBossRuntimeStartup.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/JBossRuntimeStartup.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/JBossRuntimeStartup.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -13,6 +13,8 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
@@ -20,10 +22,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.service.datalocation.Location;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IViewPart;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.navigator.CommonNavigator;
import org.jboss.tools.runtime.core.model.RuntimePath;
import org.jboss.tools.runtime.core.util.RuntimeInitializerUtil;
import org.jboss.tools.runtime.core.util.RuntimeModelUtil;
@@ -56,8 +54,9 @@
}
if (runtimePaths.size() > 0) {
- RuntimeUIActivator.getDefault().getRuntimePaths().addAll(runtimePaths);
- RuntimeUIActivator.getDefault().saveRuntimePaths();
+ HashSet<RuntimePath> set = new HashSet<RuntimePath>(Arrays.asList(RuntimeUIActivator.getDefault().getModel().getRuntimePaths()));
+ set.addAll(runtimePaths);
+ RuntimeUIActivator.getDefault().getModel().setRuntimePaths(set.toArray(new RuntimePath[set.size()]));
}
}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeCheckboxTreeViewer.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeCheckboxTreeViewer.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeCheckboxTreeViewer.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -1,6 +1,7 @@
package org.jboss.tools.runtime.ui;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Set;
@@ -18,6 +19,10 @@
public class RuntimeCheckboxTreeViewer extends CheckboxTreeViewer {
public RuntimeCheckboxTreeViewer(Composite parent, final Set<RuntimePath> runtimePaths2, int heightHint) {
+ this(parent, runtimePaths2.toArray(new RuntimePath[runtimePaths2.size()]), heightHint);
+ }
+
+ public RuntimeCheckboxTreeViewer(Composite parent, final RuntimePath[] runtimePaths2, int heightHint) {
super(parent, SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
GridData gd;
@@ -43,7 +48,7 @@
setLabelProvider(new RuntimeLabelProvider());
List<RuntimeDefinition> runtimeDefinitions = new ArrayList<RuntimeDefinition>();
for (RuntimePath runtimePath:runtimePaths2) {
- runtimeDefinitions.addAll(runtimePath.getRuntimeDefinitions());
+ runtimeDefinitions.addAll(Arrays.asList(runtimePath.getRuntimeDefinitions()));
}
setContentProvider(new RuntimeContentProvider(runtimeDefinitions));
setInput(runtimeDefinitions);
@@ -51,4 +56,17 @@
setChecked(definition, definition.isEnabled());
}
}
+
+ // Refresh your input given the following RuntimePath[]
+ public void updateInput(RuntimePath[] runtimePaths) {
+ setInput(null);
+ List<RuntimeDefinition> runtimeDefinitions = new ArrayList<RuntimeDefinition>();
+ for (RuntimePath runtimePath : runtimePaths) {
+ runtimeDefinitions.addAll(Arrays.asList(runtimePath.getRuntimeDefinitions()));
+ }
+ setInput(runtimeDefinitions);
+ for (RuntimeDefinition runtimeDefinition : runtimeDefinitions) {
+ setChecked(runtimeDefinition,runtimeDefinition.isEnabled());
+ }
+ }
}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeScanner.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeScanner.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeScanner.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -11,7 +11,6 @@
package org.jboss.tools.runtime.ui;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -49,7 +48,7 @@
}
boolean exists = runtimeExists(firstStart, monitor);
if (monitor.isCanceled()) {
- RuntimeUIActivator.getDefault().refreshRuntimePreferences();
+ RuntimeUIActivator.getDefault().getModel().setRuntimePaths(null);
return Status.CANCEL_STATUS;
}
if (exists) {
@@ -57,13 +56,15 @@
public void run() {
Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
Set<RuntimePath> runtimePaths = new HashSet<RuntimePath>();
- for (RuntimePath runtimePath:RuntimeUIActivator.getDefault().getRuntimePaths()) {
+ for (RuntimePath runtimePath:RuntimeUIActivator.getRuntimePaths()) {
if (runtimePath.isScanOnEveryStartup() || firstStart) {
runtimePaths.add(runtimePath);
}
}
+ RuntimePath[] asArr = runtimePaths.toArray(new RuntimePath[runtimePaths.size()]);
if (runtimePaths.size() > 0) {
- RuntimeUIActivator.refreshRuntimes(shell, runtimePaths, null, false, 7);
+ RuntimeUIActivator.launchSearchRuntimePathDialog(
+ shell, asArr, false, 7);
}
}
});
@@ -96,7 +97,7 @@
}
private boolean runtimeExists(boolean firstStart, IProgressMonitor monitor) {
- Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault().getRuntimePaths();
+ RuntimePath[] runtimePaths = RuntimeUIActivator.getRuntimePaths();
for (RuntimePath runtimePath:runtimePaths) {
if (!firstStart && !runtimePath.isScanOnEveryStartup()) {
continue;
@@ -109,7 +110,7 @@
RuntimeUIActivator.setTimestamp(runtimePaths);
}
monitor.setTaskName("JBoss Runtime Detector: checking " + runtimePath.getPath());
- List<RuntimeDefinition> runtimeDefinitions = runtimePath.getRuntimeDefinitions();
+ RuntimeDefinition[] runtimeDefinitions = runtimePath.getRuntimeDefinitions();
for (RuntimeDefinition runtimeDefinition:runtimeDefinitions) {
if (monitor.isCanceled()) {
return false;
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeUIActivator.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeUIActivator.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeUIActivator.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -11,32 +11,29 @@
package org.jboss.tools.runtime.ui;
import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.jboss.tools.runtime.core.RuntimeCoreActivator;
import org.jboss.tools.runtime.core.model.IRuntimeDetector;
import org.jboss.tools.runtime.core.model.RuntimeDefinition;
+import org.jboss.tools.runtime.core.model.RuntimeModel;
import org.jboss.tools.runtime.core.model.RuntimePath;
import org.jboss.tools.runtime.core.util.RuntimeInitializerUtil;
import org.jboss.tools.runtime.core.util.RuntimeModelUtil;
-import org.jboss.tools.runtime.core.util.RuntimePathPreferenceIO;
import org.jboss.tools.runtime.ui.dialogs.SearchRuntimePathDialog;
import org.jboss.tools.runtime.ui.download.DownloadRuntimes;
import org.osgi.framework.BundleContext;
@@ -73,13 +70,8 @@
private BundleContext context;
- private Set<RuntimePath> runtimePaths = new HashSet<RuntimePath>();
+ private RuntimeModel runtimeModel;
- private List<RuntimeDefinition> runtimeDefinitions;
-
- private ListenerList runtimePathChangeChangeListeners;
-
-
/**
* The constructor
*/
@@ -97,9 +89,9 @@
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
- runtimePaths = null;
this.context = context;
RuntimeCoreActivator.getDefault().setDownloader(new DownloadRuntimes());
+ runtimeModel = new RuntimeModel(getPreferences());
}
/*
@@ -109,6 +101,7 @@
public void stop(BundleContext context) throws Exception {
RuntimeCoreActivator.getDefault().setDownloader(null);
saveRuntimePreferences();
+ runtimeModel = null;
plugin = null;
super.stop(context);
}
@@ -122,9 +115,12 @@
return plugin;
}
+ public RuntimeModel getModel() {
+ return runtimeModel;
+ }
+
public static void log(Throwable e) {
- IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e
- .getLocalizedMessage(), e);
+ IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e);
RuntimeUIActivator.getDefault().getLog().log(status);
}
@@ -133,11 +129,16 @@
RuntimeUIActivator.getDefault().getLog().log(status);
}
- public static CheckboxTreeViewer createRuntimeViewer(final Set<RuntimePath> runtimePaths2, Composite composite, int heightHint) {
+ public static RuntimeCheckboxTreeViewer createRuntimeViewer(final RuntimePath[] runtimePaths2, Composite composite, int heightHint) {
return new RuntimeCheckboxTreeViewer(composite, runtimePaths2, heightHint);
}
-
- public static void refreshRuntimes(Shell shell, final Set<RuntimePath> runtimePaths, final CheckboxTreeViewer viewer, boolean needRefresh, int heightHint) {
+
+ public static RuntimeCheckboxTreeViewer createRuntimeViewer(final Set<RuntimePath> runtimePaths2, Composite composite, int heightHint) {
+ return new RuntimeCheckboxTreeViewer(composite, runtimePaths2, heightHint);
+ }
+
+ public static SearchRuntimePathDialog launchSearchRuntimePathDialog(Shell shell,
+ final RuntimePath[] runtimePaths, boolean needRefresh, int heightHint) {
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
@@ -145,52 +146,40 @@
}
};
try {
- SearchRuntimePathDialog dialog = new SearchRuntimePathDialog(shell, runtimePaths, needRefresh, heightHint);
+ HashSet<RuntimePath> set = new HashSet<RuntimePath>(Arrays.asList(runtimePaths));
+
+ SearchRuntimePathDialog dialog = new SearchRuntimePathDialog(shell, set, needRefresh, heightHint);
dialog.run(true, true, op);
- if (viewer != null) {
- dialog.getShell().addDisposeListener(new DisposeListener() {
-
- @Override
- public void widgetDisposed(DisposeEvent e) {
- viewer.setInput(null);
- List<RuntimeDefinition> runtimeDefinitions = new ArrayList<RuntimeDefinition>();
- for (RuntimePath runtimePath : runtimePaths) {
- runtimeDefinitions.addAll(runtimePath
- .getRuntimeDefinitions());
- viewer.setInput(runtimeDefinitions);
- for (RuntimeDefinition serverDefinition : runtimeDefinitions) {
- runtimeExists(serverDefinition);
- viewer.setChecked(serverDefinition,
- serverDefinition.isEnabled());
- }
- }
- }
- });
- }
+ return dialog;
} catch (InvocationTargetException e1) {
RuntimeUIActivator.log(e1);
} catch (InterruptedException e1) {
// ignore
}
+ return null;
}
+
+ public static void refreshRuntimes(Shell shell, final RuntimePath[] runtimePaths,
+ final RuntimeCheckboxTreeViewer viewer, boolean needRefresh) {
+ SearchRuntimePathDialog dialog = launchSearchRuntimePathDialog(
+ shell, runtimePaths, needRefresh, 15);
+ if (viewer != null) {
+ dialog.getShell().addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ viewer.updateInput(runtimePaths);
+ }
+ });
+ }
+ }
public static boolean runtimeExists(RuntimeDefinition runtimeDefinition) {
return RuntimeModelUtil.verifyRuntimeDefinitionCreated(runtimeDefinition, false);
}
public void saveRuntimePreferences() {
- saveRuntimePaths();
+ getModel().saveRuntimePaths();
RuntimeCoreActivator.getDefault().saveEnabledDetectors();
}
-
- private void initRuntimePaths() throws WorkbenchException {
- String runtimes = getPreferences().get(RUNTIME_PATHS, null);
- if (runtimes == null || runtimes.isEmpty()) {
- runtimePaths = new HashSet<RuntimePath>();
- return;
- }
- runtimePaths = RuntimePathPreferenceIO.loadRuntimePathsFromPreferenceString(runtimes);
- }
private static IEclipsePreferences getPreferences() {
if (prefs == null) {
@@ -199,85 +188,24 @@
return prefs;
}
- public void saveRuntimePaths() {
- if (runtimePaths == null)
- return;
-
- try {
- String runtimes = RuntimePathPreferenceIO.getPreferenceOutputString(runtimePaths);
- getPreferences().put(RUNTIME_PATHS, runtimes);
- getPreferences().flush();
- fireRuntimePathsChanged();
- } catch (Exception e) {
- log(e);
- }
- }
-
- private void fireRuntimePathsChanged() {
- if (runtimePathChangeChangeListeners != null) {
- Object[] listeners = runtimePathChangeChangeListeners.getListeners();
- for (Object listener:listeners ) {
- IRuntimePathChangeListener runtimePathChangeChangeListener = (IRuntimePathChangeListener) listener;
- runtimePathChangeChangeListener.changed();
- }
- }
- }
-
- public Set<RuntimePath> getRuntimePaths() {
- if (runtimePaths == null) {
- try {
- initRuntimePaths();
- } catch (WorkbenchException e) {
- log(e);
- runtimePaths = new HashSet<RuntimePath>();
- }
- }
- return runtimePaths;
- }
-
public List<RuntimeDefinition> getServerDefinitions() {
- if (runtimeDefinitions == null) {
- runtimeDefinitions = new ArrayList<RuntimeDefinition>();
- } else {
- runtimeDefinitions.clear();
- }
- for (RuntimePath runtimePath:getRuntimePaths()) {
- runtimeDefinitions.addAll(runtimePath.getRuntimeDefinitions());
- }
- return runtimeDefinitions;
+ return RuntimeModelUtil.getRuntimeDefinitions(runtimeModel.getRuntimePaths());
}
public Set<IRuntimeDetector> getRuntimeDetectors() {
return RuntimeCoreActivator.getDefault().getRuntimeDetectors();
}
- public void initDefaultRuntimePreferences() {
- runtimePaths = new HashSet<RuntimePath>();
- }
-
- public static void setTimestamp(Set<RuntimePath> runtimePaths2) {
+ public static void setTimestamp(RuntimePath[] runtimePaths2) {
RuntimeModelUtil.updateTimestamps(runtimePaths2);
}
- public void refreshRuntimePreferences() {
- runtimePaths = null;
- }
-
public static boolean runtimeCreated(RuntimeDefinition runtimeDefinition) {
return RuntimeModelUtil.verifyRuntimeDefinitionCreated(runtimeDefinition);
}
- public void addRuntimePathChangeListener(IRuntimePathChangeListener listener) {
- if (runtimePathChangeChangeListeners == null)
- runtimePathChangeChangeListeners = new ListenerList();
- runtimePathChangeChangeListeners.add(listener);
+ public static RuntimePath[] getRuntimePaths() {
+ return getDefault().getModel().getRuntimePaths();
}
- public void removeRuntimePathChangeListener(IRuntimePathChangeListener listener) {
- if (runtimePathChangeChangeListeners == null)
- return;
- runtimePathChangeChangeListeners.remove(listener);
- if (runtimePathChangeChangeListeners.size() == 0)
- runtimePathChangeChangeListeners = null;
- }
}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeWorkbenchUtils.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeWorkbenchUtils.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeWorkbenchUtils.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -32,8 +32,7 @@
}
public static void refreshPreferencePageUIThread(Shell shell) {
- Shell mainShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getShell();
+ Shell mainShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
if (shell != null && !shell.isDisposed()) {
shell.close();
}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/EditRuntimePathDialog.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/EditRuntimePathDialog.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/EditRuntimePathDialog.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -11,13 +11,10 @@
package org.jboss.tools.runtime.ui.dialogs;
import java.io.File;
-import java.util.HashSet;
-import java.util.Set;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
@@ -33,8 +30,9 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import org.jboss.tools.runtime.core.model.RuntimePath;
import org.jboss.tools.runtime.core.model.RuntimeDefinition;
+import org.jboss.tools.runtime.core.model.RuntimePath;
+import org.jboss.tools.runtime.ui.RuntimeCheckboxTreeViewer;
import org.jboss.tools.runtime.ui.RuntimeUIActivator;
/**
@@ -44,8 +42,7 @@
public class EditRuntimePathDialog extends Dialog {
private RuntimePath runtimePath;
- private Set<RuntimePath> runtimePaths;
- private CheckboxTreeViewer treeViewer;
+ private RuntimeCheckboxTreeViewer treeViewer;
public EditRuntimePathDialog(Shell parentShell, RuntimePath runtimePath) {
super(parentShell);
@@ -97,14 +94,8 @@
runtimePath.setPath(path);
dialogSettings.put(RuntimeUIActivator.LASTPATH, path);
pathText.setText(path);
-// Set<RuntimePath> runtimePaths2 = new HashSet<RuntimePath>();
-// RuntimePath runtimePath2 = new RuntimePath(path);
-// runtimePath2.setScanOnEveryStartup(runtimePath.isScanOnEveryStartup());
-// runtimePaths2.add(runtimePath2);
- RuntimeUIActivator.refreshRuntimes(getShell(), runtimePaths, treeViewer, false, 15);
-
-// runtimePath = runtimePath2;
-// runtimePaths = runtimePaths2;
+ RuntimeUIActivator.refreshRuntimes(getShell(),
+ new RuntimePath[]{runtimePath}, treeViewer, false);
}
});
@@ -118,17 +109,13 @@
final Button refreshButton = new Button(pathComposite, SWT.NONE);
refreshButton.setText("Refresh...");
refreshButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
public void widgetSelected(SelectionEvent e) {
- RuntimeUIActivator.refreshRuntimes(getShell(), getRuntimePaths(), treeViewer, false, 15);
+ RuntimeUIActivator.refreshRuntimes(getShell(),
+ new RuntimePath[]{runtimePath}, treeViewer, false);
}
-
});
pathText.addModifyListener(new ModifyListener() {
-
- @Override
public void modifyText(ModifyEvent e) {
runtimePath.setPath(pathText.getText());
if (!pathText.getText().isEmpty()) {
@@ -138,11 +125,8 @@
});
refreshButton.setEnabled( (new File(pathText.getText()).isDirectory()) );
- Set<RuntimePath> runtimePaths = getRuntimePaths();
- treeViewer = RuntimeUIActivator.createRuntimeViewer(runtimePaths, contents, 100);
+ treeViewer = RuntimeUIActivator.createRuntimeViewer(new RuntimePath[]{runtimePath}, contents, 100);
treeViewer.addCheckStateListener(new ICheckStateListener() {
-
- @Override
public void checkStateChanged(CheckStateChangedEvent event) {
RuntimeDefinition definition = (RuntimeDefinition) event.getElement();
definition.setEnabled(!definition.isEnabled());
@@ -151,12 +135,5 @@
return area;
}
- private Set<RuntimePath> getRuntimePaths() {
- if (runtimePaths == null) {
- runtimePaths = new HashSet<RuntimePath>();
- runtimePaths.add(runtimePath);
- }
- return runtimePaths;
- }
}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/SearchRuntimePathDialog.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/SearchRuntimePathDialog.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/SearchRuntimePathDialog.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -10,12 +10,16 @@
************************************************************************************/
package org.jboss.tools.runtime.ui.dialogs;
-import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.ProgressIndicator;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
@@ -41,10 +45,10 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TreeItem;
-import org.jboss.tools.runtime.core.RuntimeCoreActivator;
-import org.jboss.tools.runtime.core.model.IRuntimeDetector;
import org.jboss.tools.runtime.core.model.RuntimeDefinition;
import org.jboss.tools.runtime.core.model.RuntimePath;
+import org.jboss.tools.runtime.core.util.RuntimeInitializerUtil;
+import org.jboss.tools.runtime.core.util.RuntimeModelUtil;
import org.jboss.tools.runtime.ui.RuntimeUIActivator;
import org.jboss.tools.runtime.ui.RuntimeWorkbenchUtils;
@@ -60,7 +64,6 @@
private boolean canceled;
private boolean needRefresh;
private Label foundRuntimesLabel;
- private List<RuntimeDefinition> runtimeDefinitions;
private Button hideCreatedRuntimes;
private int heightHint;
@@ -124,24 +127,7 @@
public void checkStateChanged(CheckStateChangedEvent event) {
RuntimeDefinition definition = (RuntimeDefinition) event.getElement();
definition.setEnabled(!definition.isEnabled());
- boolean enableOk = false;
- List<RuntimeDefinition> serverDefinitions = getRuntimeDefinitions(hideCreatedRuntimes.getSelection());
- for (RuntimeDefinition serverDefinition:serverDefinitions) {
- if (serverDefinition.isEnabled()) {
- enableOk = true;
- } else {
- for (RuntimeDefinition includedDefinition:serverDefinition.getIncludedRuntimeDefinitions()) {
- if (includedDefinition.isEnabled()) {
- enableOk = true;
- break;
- }
- }
- }
- if (enableOk) {
- break;
- }
- }
- getButton(IDialogConstants.OK_ID).setEnabled(enableOk);
+ getButton(IDialogConstants.OK_ID).setEnabled(anyDefinitionsChecked());
}
});
@@ -191,8 +177,29 @@
});
return parent;
-
}
+
+ /* are there any definitions enabled / checked? */
+ private boolean anyDefinitionsChecked() {
+ boolean enableOk = false;
+ List<RuntimeDefinition> runtimeDefinitions = getRuntimeDefinitions(hideCreatedRuntimes.getSelection());
+ for (RuntimeDefinition runtimeDefinition:runtimeDefinitions) {
+ if (runtimeDefinition.isEnabled()) {
+ enableOk = true;
+ } else {
+ for (RuntimeDefinition includedDefinition:runtimeDefinition.getIncludedRuntimeDefinitions()) {
+ if (includedDefinition.isEnabled()) {
+ enableOk = true;
+ break;
+ }
+ }
+ }
+ if (enableOk) {
+ break;
+ }
+ }
+ return enableOk;
+ }
@Override
protected void createButtonsForButtonBar(Composite parent) {
@@ -229,9 +236,9 @@
private void refresh(String message) {
running = false;
treeViewer.setInput(null);
- List<RuntimeDefinition> serverDefinitions = getRuntimeDefinitions(hideCreatedRuntimes.getSelection());
- treeViewer.setInput(serverDefinitions);
- for (RuntimeDefinition definition:serverDefinitions) {
+ List<RuntimeDefinition> runtimeDefinitions = getRuntimeDefinitions(hideCreatedRuntimes.getSelection());
+ treeViewer.setInput(runtimeDefinitions);
+ for (RuntimeDefinition definition:runtimeDefinitions) {
treeViewer.setChecked(definition, definition.isEnabled());
for (RuntimeDefinition included:definition.getIncludedRuntimeDefinitions()) {
treeViewer.setChecked(included, included.isEnabled());
@@ -241,11 +248,11 @@
for (TreeItem treeItem:treeItems) {
Object data = treeItem.getData();
if (data instanceof RuntimeDefinition) {
- RuntimeDefinition serverDefinition = (RuntimeDefinition) data;
- boolean exists = RuntimeUIActivator.runtimeExists(serverDefinition);
+ RuntimeDefinition runtimeDefinition = (RuntimeDefinition) data;
+ boolean exists = RuntimeUIActivator.runtimeExists(runtimeDefinition);
if (exists) {
treeItem.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
- treeViewer.setChecked(serverDefinition, serverDefinition.isEnabled());
+ treeViewer.setChecked(runtimeDefinition, runtimeDefinition.isEnabled());
}
}
}
@@ -257,19 +264,25 @@
@Override
protected void okPressed() {
getShell().setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_WAIT));
- Set<IRuntimeDetector> detectors = RuntimeCoreActivator.getDefault().getRuntimeDetectors();
- List<RuntimeDefinition> definitions = getRuntimeDefinitions(true);
- for( IRuntimeDetector detector:detectors) {
- if (detector.isEnabled()) {
- detector.initializeRuntimes(definitions);
- }
- }
+
+ // Get the definitions to be initialized
+ final List<RuntimeDefinition> definitions = getEnabledRuntimeDefinitions();
+
getShell().setCursor(null);
setReturnCode(OK);
close();
- if (needRefresh) {
- RuntimeWorkbenchUtils.refreshPreferencePage(getShell());
- }
+
+ final boolean needRefresh = this.needRefresh;
+ new Job("Initializing runtimes...") {
+ protected IStatus run(IProgressMonitor monitor) {
+ RuntimeInitializerUtil.initializeRuntimes(definitions);
+ if (needRefresh) {
+ // Util class runs this in ui thread
+ RuntimeWorkbenchUtils.refreshPreferencePage(getShell());
+ }
+ return Status.OK_STATUS;
+ }
+ }.schedule();
}
@Override
@@ -287,7 +300,7 @@
refresh("Searching runtimes is canceled.");
} else {
refresh("Searching runtimes is finished.");
- RuntimeUIActivator.setTimestamp(runtimePaths);
+ RuntimeUIActivator.setTimestamp(runtimePaths.toArray(new RuntimePath[runtimePaths.size()]));
}
String foundRuntimes;
@@ -325,33 +338,43 @@
return composite;
}
- private List<RuntimeDefinition> getRuntimeDefinitions(
- boolean hideCreatedRuntimes) {
- if (runtimeDefinitions == null) {
- runtimeDefinitions = new ArrayList<RuntimeDefinition>();
- } else {
- runtimeDefinitions.clear();
+ private List<RuntimeDefinition> getEnabledRuntimeDefinitions() {
+ ArrayList<RuntimeDefinition> all = getRuntimeDefinitions(true);
+ Iterator<RuntimeDefinition> i = all.iterator();
+ while(i.hasNext()) {
+ if( !i.next().isEnabled())
+ i.remove();
}
- List<RuntimeDefinition> allDefinitions = getAllDefinitions();
+ return all;
+ }
+
+ private ArrayList<RuntimeDefinition> getRuntimeDefinitions(
+ boolean hideCreatedRuntimes) {
+ ArrayList<RuntimeDefinition> runtimeDefinitions = new ArrayList<RuntimeDefinition>();
+
+ // It seems the intent of this block is to increment a name on a runtime definition,
+ // however, the model it's pulling a runtime definition from the list of all definitions.
+ // IF the items are ==, they will continue to be == even after a name change ?!
+// List<RuntimeDefinition> allDefinitions = getAllDefinitions();
+// for (RuntimePath runtimePath : runtimePaths) {
+// List<RuntimeDefinition> pathDefinitions = getAllDefinitions(runtimePath);
+// for (RuntimeDefinition runtimeDefinition : pathDefinitions) {
+// if (!RuntimeUIActivator.runtimeCreated(runtimeDefinition)) {
+// String name = runtimeDefinition.getName();
+// int i = 2;
+// while (runtimeDefinitionsExists(runtimeDefinition, allDefinitions)) {
+// runtimeDefinition.setName(name + " (" + i++ + ")");
+// }
+// }
+// }
+// }
+
for (RuntimePath runtimePath : runtimePaths) {
- List<RuntimeDefinition> pathDefinitions = getAllDefinitions(runtimePath);
- for (RuntimeDefinition runtimeDefinition : pathDefinitions) {
- if (!RuntimeUIActivator.runtimeCreated(runtimeDefinition)) {
- String name = runtimeDefinition.getName();
- int i = 2;
- while (runtimeDefinitionsExists(runtimeDefinition, allDefinitions)) {
- runtimeDefinition.setName(name + " (" + i++ + ")");
- }
- }
- }
-
- }
- for (RuntimePath runtimePath : runtimePaths) {
- for (RuntimeDefinition serverDefinition : runtimePath.getRuntimeDefinitions()) {
+ for (RuntimeDefinition runtimeDefinition : runtimePath.getRuntimeDefinitions()) {
if (!hideCreatedRuntimes) {
- runtimeDefinitions.add(serverDefinition);
- } else if (!RuntimeUIActivator.runtimeCreated(serverDefinition)) {
- runtimeDefinitions.add(serverDefinition);
+ runtimeDefinitions.add(runtimeDefinition);
+ } else if (!RuntimeUIActivator.runtimeCreated(runtimeDefinition)) {
+ runtimeDefinitions.add(runtimeDefinition);
}
}
}
@@ -359,51 +382,15 @@
}
protected List<RuntimeDefinition> getAllDefinitions(RuntimePath runtimePath) {
- List<RuntimeDefinition> allDefinitions = new ArrayList<RuntimeDefinition>();
- allDefinitions.addAll(runtimePath.getRuntimeDefinitions());
- for (RuntimeDefinition serverDefinition : runtimePath.getRuntimeDefinitions()) {
- allDefinitions.addAll(serverDefinition.getIncludedRuntimeDefinitions());
- }
- return allDefinitions;
+ return RuntimeModelUtil.getAllDefinitions(runtimePath);
}
private List<RuntimeDefinition> getAllDefinitions() {
- List<RuntimeDefinition> allServerDefinitions = new ArrayList<RuntimeDefinition>();
- allServerDefinitions.addAll(RuntimeUIActivator.getDefault().getServerDefinitions());
- for (RuntimeDefinition d:RuntimeUIActivator.getDefault().getServerDefinitions()) {
- allServerDefinitions.addAll(d.getIncludedRuntimeDefinitions());
- }
- return allServerDefinitions;
+ return RuntimeModelUtil.getAllDefinitions(RuntimeUIActivator.getRuntimePaths());
}
- private boolean runtimeDefinitionsExists(RuntimeDefinition serverDefinition,
- List<RuntimeDefinition> allServerDefinitions) {
- String name = serverDefinition.getName();
- File location = serverDefinition.getLocation();
- String type = serverDefinition.getType();
- if (name == null || location == null || type == null) {
- return false;
- }
- String path = location.getAbsolutePath();
- if (path == null) {
- return false;
- }
- for (RuntimeDefinition definition:allServerDefinitions) {
- if (name.equals(definition.getName()) && type.equals(definition.getType())) {
- File loc = definition.getLocation();
- if (loc == null) {
- continue;
- }
- String dPath = loc.getAbsolutePath();
- if (dPath == null) {
- continue;
- }
- if (!path.equals(dPath)) {
- return true;
- }
- }
- }
- return false;
+ private boolean runtimeDefinitionsExists(RuntimeDefinition runtimeDefinition,List<RuntimeDefinition> allRuntimeDefinitions) {
+ return RuntimeModelUtil.runtimeDefinitionsExists(runtimeDefinition, allRuntimeDefinitions);
}
}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/download/DownloadRuntimeDialog.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/download/DownloadRuntimeDialog.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/download/DownloadRuntimeDialog.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -19,7 +19,6 @@
import java.net.URL;
import java.util.Enumeration;
import java.util.List;
-import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -56,13 +55,11 @@
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import org.eclipse.ui.progress.IProgressService;
import org.jboss.tools.common.zip.UnzipOperation;
-import org.jboss.tools.runtime.core.JBossRuntimeLocator;
-import org.jboss.tools.runtime.core.RuntimeCoreActivator;
import org.jboss.tools.runtime.core.model.DownloadRuntime;
-import org.jboss.tools.runtime.core.model.IRuntimeDetector;
import org.jboss.tools.runtime.core.model.RuntimeDefinition;
import org.jboss.tools.runtime.core.model.RuntimePath;
import org.jboss.tools.runtime.core.util.ECFTransport;
+import org.jboss.tools.runtime.core.util.RuntimeInitializerUtil;
import org.jboss.tools.runtime.ui.RuntimeUIActivator;
/**
@@ -547,48 +544,33 @@
private static void createRuntimes(String directory,
IProgressMonitor monitor) {
- JBossRuntimeLocator locator = new JBossRuntimeLocator();
final RuntimePath runtimePath = new RuntimePath(directory);
- List<RuntimeDefinition> serverDefinitions = locator.searchForRuntimes(
- runtimePath.getPath(), monitor);
- runtimePath.getRuntimeDefinitions().clear();
- for (RuntimeDefinition serverDefinition : serverDefinitions) {
- serverDefinition.setRuntimePath(runtimePath);
- }
- runtimePath.getRuntimeDefinitions().addAll(serverDefinitions);
- RuntimeUIActivator.getDefault().getRuntimePaths().add(runtimePath);
- RuntimeUIActivator.getDefault().saveRuntimePaths();
- if (serverDefinitions.size() == 0) {
+ List<RuntimeDefinition> runtimeDefinitions = RuntimeInitializerUtil.createRuntimeDefinitions(runtimePath, monitor);
+ RuntimeUIActivator.getDefault().getModel().addRuntimePath(runtimePath);
+ if (runtimeDefinitions.size() == 0) {
+ openRuntimeNotFoundMessage();
+ } else if (runtimeDefinitions.size() > 1) {
Display.getDefault().asyncExec(new Runnable() {
-
- @Override
public void run() {
- MessageDialog.openError(Display.getDefault()
- .getActiveShell(), "Error", "No runtime/server found...");
+ RuntimeUIActivator.launchSearchRuntimePathDialog(
+ Display.getDefault().getActiveShell(),
+ RuntimeUIActivator.getRuntimePaths(), false, 7);
}
});
+ } else /* size == 1 */{
+ RuntimeInitializerUtil.initializeRuntimes(runtimeDefinitions);
}
- if (serverDefinitions.size() > 1) {
- Display.getDefault().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- RuntimeUIActivator.refreshRuntimes(Display.getDefault()
- .getActiveShell(), RuntimeUIActivator.getDefault().getRuntimePaths(), null, false, 7);
- }
- });
-
- } else {
- Set<IRuntimeDetector> detectors = RuntimeCoreActivator.getDefault()
- .getRuntimeDetectors();
- for (IRuntimeDetector detector : detectors) {
- if (detector.isEnabled()) {
- detector.initializeRuntimes(serverDefinitions);
- }
- }
- }
}
+ private static void openRuntimeNotFoundMessage() {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ MessageDialog.openError(Display.getDefault()
+ .getActiveShell(), "Error", "No runtime/server found...");
+ }
+ });
+ }
+
@Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/download/DownloadRuntimes.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/download/DownloadRuntimes.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/download/DownloadRuntimes.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -15,6 +15,11 @@
public void execute(HashMap<String, Object> map) {
Object shell = map.get(SHELL);
Shell shell2 = shell == null ? Display.getDefault().getActiveShell() : ((Shell)shell);
+
+ // If this has not been accessed before, this may freeze the UI during
+ // a fetch to the remote path. The call to get the downloadable runtimes
+ // also fetches from a remote repository location.
+ // THis should also be done via a display.asynchexec
DownloadRuntimeViewerDialog dialog = new DownloadRuntimeViewerDialog(shell2);
dialog.open();
}
Modified: trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/preferences/RuntimePreferencePage.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/preferences/RuntimePreferencePage.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/preferences/RuntimePreferencePage.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -11,8 +11,9 @@
package org.jboss.tools.runtime.ui.preferences;
import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -74,11 +75,10 @@
import org.jboss.tools.runtime.core.RuntimeCoreActivator;
import org.jboss.tools.runtime.core.model.IDownloadRuntimes;
import org.jboss.tools.runtime.core.model.IRuntimeDetector;
+import org.jboss.tools.runtime.core.model.IRuntimePathChangeListener;
import org.jboss.tools.runtime.core.model.RuntimePath;
-import org.jboss.tools.runtime.ui.IRuntimePathChangeListener;
import org.jboss.tools.runtime.ui.RuntimeSharedImages;
import org.jboss.tools.runtime.ui.RuntimeUIActivator;
-import org.jboss.tools.runtime.ui.RuntimeWorkbenchUtils;
import org.jboss.tools.runtime.ui.dialogs.AutoResizeTableLayout;
import org.jboss.tools.runtime.ui.dialogs.EditRuntimePathDialog;
import org.jboss.tools.runtime.ui.dialogs.RuntimePathEditingSupport;
@@ -92,7 +92,7 @@
IWorkbenchPreferencePage {
public static String ID = "org.jboss.tools.runtime.preferences.RuntimePreferencePage";
- private Set<RuntimePath> runtimePaths = new HashSet<RuntimePath>();
+ private RuntimePath[] runtimePaths = new RuntimePath[0];
private TableViewer runtimePathViewer;
private RuntimePath runtimePath;
private Set<IRuntimeDetector> runtimeDetectors;
@@ -255,26 +255,18 @@
createRuntimePathsButtons(parent, viewer);
runtimePathChangeListener = new IRuntimePathChangeListener() {
-
- @Override
public void changed() {
-
Display.getDefault().asyncExec(new Runnable() {
-
- @Override
public void run() {
- if (runtimePathChangeListener == null) {
- return;
+ if (runtimePathChangeListener != null) {
+ viewer.setInput(RuntimeUIActivator.getRuntimePaths());
}
- runtimePaths = RuntimeUIActivator.getDefault().getRuntimePaths();
- viewer.setInput(runtimePaths);
- viewer.refresh();
}
});
}
};
- RuntimeUIActivator.getDefault().addRuntimePathChangeListener(runtimePathChangeListener);
+ RuntimeUIActivator.getDefault().getModel().addRuntimePathChangeListener(runtimePathChangeListener);
return viewer;
}
@@ -308,40 +300,10 @@
Button addButton = new Button(buttonComposite, SWT.PUSH);
addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
addButton.setText("Add");
- addButton.addSelectionListener(new SelectionListener(){
-
- public void widgetDefaultSelected(SelectionEvent e) {
-
- }
-
+ addButton.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
- IDialogSettings dialogSettings = RuntimeUIActivator.getDefault().getDialogSettings();
- String lastUsedPath= dialogSettings.get(RuntimeUIActivator.LASTPATH);
- if (lastUsedPath == null) {
- lastUsedPath= ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();
- }
- DirectoryDialog dialog = new DirectoryDialog(getShell());
- dialog.setMessage("Add a new path");
- dialog.setFilterPath(lastUsedPath);
- final String path = dialog.open();
- if (path == null) {
- return;
- }
- dialogSettings.put(RuntimeUIActivator.LASTPATH, path);
- RuntimePath runtimePath = new RuntimePath(path);
- boolean exists = runtimePaths.add(runtimePath);
- if (!exists) {
- MessageDialog.openInformation(getShell(), "Add Runtime Path", "This runtime path already exists");
- return;
- }
- Set<RuntimePath> runtimePaths2 = new HashSet<RuntimePath>();
- runtimePaths2.add(runtimePath);
- RuntimeUIActivator.refreshRuntimes(getShell(), runtimePaths2, null, true, 15);
- configureSearch();
- runtimePathViewer.setInput(runtimePath.getRuntimeDefinitions());
- viewer.refresh();
+ addPressed();
}
-
});
final Button editButton = new Button(buttonComposite, SWT.PUSH);
@@ -349,48 +311,10 @@
editButton.setText("Edit...");
editButton.setEnabled(false);
- editButton.addSelectionListener(new SelectionListener(){
-
+ editButton.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
- ISelection sel = viewer.getSelection();
- if (sel instanceof IStructuredSelection) {
- IStructuredSelection selection = (IStructuredSelection) sel;
- Object object = selection.getFirstElement();
- if (object instanceof RuntimePath) {
- runtimePath = (RuntimePath) object;
- RuntimePath runtimePathClone;
- try {
- runtimePathClone = (RuntimePath) runtimePath.clone();
- } catch (CloneNotSupportedException e1) {
- RuntimeUIActivator.log(e1);
- runtimePathClone = runtimePath;
- }
- EditRuntimePathDialog dialog = new EditRuntimePathDialog(getShell(), runtimePathClone);
- int ok = dialog.open();
- if (ok == Window.OK) {
- if (runtimePath.equals(runtimePathClone)) {
- return;
- }
- if (runtimePaths.contains(runtimePathClone)) {
- MessageDialog.openInformation(getShell(), "Edit Runtime Path", "This runtime path already exists");
- return;
- }
- runtimePaths.remove(runtimePath);
- runtimePath = runtimePathClone;
- runtimePaths.add(runtimePath);
- configureSearch();
- viewer.refresh();
- }
- }
- }
- if (!getControl().isDisposed()) {
- RuntimeWorkbenchUtils.refreshPreferencePageUIThread(getShell());
- }
+ editPressed();
}
-
- public void widgetDefaultSelected(SelectionEvent e) {
-
- }
});
final Button removeButton = new Button(buttonComposite, SWT.PUSH);
@@ -398,40 +322,21 @@
removeButton.setText("Remove");
removeButton.setEnabled(false);
- removeButton.addSelectionListener(new SelectionListener(){
-
+ removeButton.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
- ISelection sel = viewer.getSelection();
- if (sel instanceof IStructuredSelection) {
- IStructuredSelection selection = (IStructuredSelection) sel;
- Object object = selection.getFirstElement();
- if (object instanceof RuntimePath) {
- runtimePaths.remove(object);
- configureSearch();
- viewer.refresh();
- }
- }
+ removedPressed();
}
-
- public void widgetDefaultSelected(SelectionEvent e) {
-
- }
});
searchButton = new Button(buttonComposite, SWT.PUSH);
searchButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
searchButton.setText("Search...");
- searchButton.setEnabled(runtimePaths.size() > 0);
-
- searchButton.addSelectionListener(new SelectionListener(){
-
+ searchButton.setEnabled(runtimePaths.length > 0);
+ searchButton.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
- RuntimeUIActivator.refreshRuntimes(getShell(), runtimePaths, null, true, 15);
+ RuntimeUIActivator.launchSearchRuntimePathDialog(getShell(),
+ runtimePaths, true, 15);
}
-
- public void widgetDefaultSelected(SelectionEvent e) {
-
- }
});
downloadButton = new Button(buttonComposite, SWT.PUSH);
@@ -471,21 +376,103 @@
});
}
+ private void addPressed() {
+ IDialogSettings dialogSettings = RuntimeUIActivator.getDefault().getDialogSettings();
+ String lastUsedPath= dialogSettings.get(RuntimeUIActivator.LASTPATH);
+ if (lastUsedPath == null) {
+ lastUsedPath= ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();
+ }
+ DirectoryDialog dialog = new DirectoryDialog(getShell());
+ dialog.setMessage("Add a new path");
+ dialog.setFilterPath(lastUsedPath);
+ final String path = dialog.open();
+ if (path == null) {
+ return;
+ }
+ dialogSettings.put(RuntimeUIActivator.LASTPATH, path);
+ RuntimePath runtimePath = new RuntimePath(path);
+ boolean exists = Arrays.asList(runtimePaths).contains(runtimePath);
+ if (exists) {
+ MessageDialog.openInformation(getShell(), "Add Runtime Path", "This runtime path already exists");
+ return;
+ }
+ RuntimeUIActivator.launchSearchRuntimePathDialog(getShell(),
+ new RuntimePath[]{runtimePath}, true, 15);
+ configureSearch();
+ runtimePathViewer.setInput(runtimePath.getRuntimeDefinitions());
+ runtimePathViewer.refresh();
+ }
+
+ private void removedPressed() {
+ ISelection sel = runtimePathViewer.getSelection();
+ if (sel instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection) sel;
+ Object object = selection.getFirstElement();
+ if (object instanceof RuntimePath) {
+ ArrayList<RuntimePath> l = new ArrayList<RuntimePath>(Arrays.asList(runtimePaths));
+ l.remove(object);
+ runtimePaths = (RuntimePath[]) l.toArray(new RuntimePath[l.size()]);
+ configureSearch();
+ runtimePathViewer.refresh();
+ }
+ }
+ }
+
+ private void editPressed() {
+ ISelection sel = runtimePathViewer.getSelection();
+ if (sel instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection) sel;
+ Object object = selection.getFirstElement();
+ if (object instanceof RuntimePath) {
+ runtimePath = (RuntimePath) object;
+ RuntimePath runtimePathClone;
+ try {
+ runtimePathClone = (RuntimePath) runtimePath.clone();
+ } catch (CloneNotSupportedException e1) {
+ RuntimeUIActivator.log(e1);
+ runtimePathClone = runtimePath;
+ }
+ EditRuntimePathDialog dialog = new EditRuntimePathDialog(getShell(), runtimePathClone);
+ int ok = dialog.open();
+ if (ok == Window.OK) {
+ if (runtimePath.equals(runtimePathClone)) {
+ return;
+ }
+ if (Arrays.asList(runtimePaths).contains(runtimePathClone)) {
+ MessageDialog.openInformation(getShell(), "Edit Runtime Path", "This runtime path already exists");
+ return;
+ }
+
+ ArrayList<RuntimePath> l = new ArrayList<RuntimePath>(Arrays.asList(runtimePaths));
+ l.remove(runtimePath);
+ runtimePath = runtimePathClone;
+ l.add(runtimePath);
+ runtimePaths = (RuntimePath[]) l.toArray(new RuntimePath[l.size()]);
+ configureSearch();
+ runtimePathViewer.refresh();
+ }
+ }
+ }
+ // IS THIS NEEDED?!?!
+// if (!getControl().isDisposed()) {
+// RuntimeWorkbenchUtils.refreshPreferencePageUIThread(getShell());
+// }
+ }
+
+
private IDownloadRuntimes getDownloader() {
return RuntimeCoreActivator.getDefault().getDownloader();
}
public void init(IWorkbench workbench) {
- runtimePaths = RuntimeUIActivator.getDefault().getRuntimePaths();
+ runtimePaths = RuntimeUIActivator.getDefault().getModel().getRuntimePaths();
runtimeDetectors = RuntimeUIActivator.getDefault().getRuntimeDetectors();
}
@Override
public void dispose() {
- if (runtimePathChangeListener != null) {
- RuntimeUIActivator.getDefault().removeRuntimePathChangeListener(runtimePathChangeListener);
- runtimePathChangeListener = null;
- }
+ RuntimeUIActivator.getDefault().getModel().removeRuntimePathChangeListener(runtimePathChangeListener);
+ runtimePathChangeListener = null;
super.dispose();
}
@@ -518,22 +505,13 @@
}
class RuntimePathContentProvider implements IStructuredContentProvider {
-
- @Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
}
-
- @Override
public Object[] getElements(Object inputElement) {
- return runtimePaths.toArray();
+ return runtimePaths;
}
-
- @Override
public void dispose() {
-
}
-
}
public static class RuntimePathLabelProvider extends ColumnLabelProvider {
@@ -623,8 +601,7 @@
@Override
protected void performDefaults() {
- RuntimeUIActivator.getDefault().initDefaultRuntimePreferences();
- runtimePaths = RuntimeUIActivator.getDefault().getRuntimePaths();
+ runtimePaths = RuntimeUIActivator.getDefault().getModel().getRuntimePaths();
runtimeDetectors = RuntimeUIActivator.getDefault().getRuntimeDetectors();
runtimePathViewer.setInput(runtimePaths);
detectorViewer.setInput(runtimeDetectors);
@@ -633,13 +610,14 @@
@Override
public boolean performOk() {
+ RuntimeUIActivator.getDefault().getModel().setRuntimePaths(runtimePaths);
RuntimeUIActivator.getDefault().saveRuntimePreferences();
return super.performOk();
}
private void configureSearch() {
if (searchButton != null) {
- searchButton.setEnabled(runtimePaths.size() > 0);
+ searchButton.setEnabled(runtimePaths.length > 0);
}
}
Modified: trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/dialog/preferences/RuntimeDetectionPreferencesDialog.java
===================================================================
--- trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/dialog/preferences/RuntimeDetectionPreferencesDialog.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/dialog/preferences/RuntimeDetectionPreferencesDialog.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -1,7 +1,5 @@
package org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences;
-import java.util.Set;
-
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
@@ -24,9 +22,7 @@
@Override
public void run() {
- Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault().getRuntimePaths();
- runtimePaths.add(new RuntimePath(path));
- RuntimeUIActivator.getDefault().saveRuntimePaths();
+ RuntimeUIActivator.getDefault().getModel().addRuntimePath(new RuntimePath(path));
}
});
Modified: trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionFrameworkTest.java
===================================================================
--- trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionFrameworkTest.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionFrameworkTest.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -58,7 +58,7 @@
assertFalse("Invalid detector is enabled.", invalidDetector.isEnabled());
}
- private String displayRuntimes(Set<RuntimePath> paths) {
+ private String displayRuntimes(RuntimePath[] paths) {
String s = "";
for(RuntimePath path:paths) {
s += path.getPath() + "\n";
@@ -69,20 +69,19 @@
@Test
public void testLoadSaveRuntimePaths() {
String path = "test/path/one";
- Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault().getRuntimePaths();
- assertEquals(displayRuntimes(runtimePaths), 0, runtimePaths.size());
+ RuntimePath[] runtimePaths = RuntimeUIActivator.getRuntimePaths();
+ assertEquals(displayRuntimes(runtimePaths), 0, runtimePaths.length);
RuntimePath runtimePath = new RuntimePath(path);
runtimePath.setScanOnEveryStartup(false);
- runtimePaths.add(runtimePath);
- RuntimeUIActivator.getDefault().saveRuntimePaths();
+ RuntimeUIActivator.getDefault().getModel().addRuntimePath(runtimePath);
+ RuntimeUIActivator.getDefault().getModel().saveRuntimePaths();
restartBundle();
- runtimePaths = RuntimeUIActivator.getDefault().getRuntimePaths();
- assertEquals(1, runtimePaths.size());
- runtimePaths.clear();
- RuntimeUIActivator.getDefault().saveRuntimePaths();
+ runtimePaths = RuntimeUIActivator.getRuntimePaths();
+ assertEquals(1, runtimePaths.length);
+ RuntimeUIActivator.getDefault().getModel().setRuntimePaths(new RuntimePath[]{});
restartBundle();
- runtimePaths = RuntimeUIActivator.getDefault().getRuntimePaths();
- assertEquals(0, runtimePaths.size());
+ runtimePaths = RuntimeUIActivator.getRuntimePaths();
+ assertEquals(0, runtimePaths.length);
}
private void restartBundle() {
Modified: trunk/runtime-soa/tests/org.jboss.tools.runtime.soa.test/src/org/jboss/tools/runtime/test/RuntimeDetectionTest.java
===================================================================
--- trunk/runtime-soa/tests/org.jboss.tools.runtime.soa.test/src/org/jboss/tools/runtime/test/RuntimeDetectionTest.java 2012-09-10 00:51:29 UTC (rev 43543)
+++ trunk/runtime-soa/tests/org.jboss.tools.runtime.soa.test/src/org/jboss/tools/runtime/test/RuntimeDetectionTest.java 2012-09-10 07:43:29 UTC (rev 43544)
@@ -43,8 +43,8 @@
import org.jboss.tools.runtime.core.RuntimeCoreActivator;
import org.jboss.tools.runtime.core.internal.InvalidRuntimeDetector;
import org.jboss.tools.runtime.core.model.IRuntimeDetector;
-import org.jboss.tools.runtime.core.model.RuntimePath;
import org.jboss.tools.runtime.core.model.RuntimeDefinition;
+import org.jboss.tools.runtime.core.model.RuntimePath;
import org.jboss.tools.runtime.ui.RuntimeUIActivator;
import org.jboss.tools.seam.core.project.facet.SeamRuntime;
import org.jboss.tools.seam.core.project.facet.SeamRuntimeManager;
@@ -75,8 +75,7 @@
}
private static void addRuntimePaths() {
- Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
- .getRuntimePaths();
+ RuntimePath[] runtimePaths = RuntimeUIActivator.getRuntimePaths();
String[] paths = { IRuntimeDetectionConstants.JBOSS_42_HOME,
IRuntimeDetectionConstants.JBOSS_51_HOME,
IRuntimeDetectionConstants.JBOSS_70_HOME,
@@ -134,17 +133,15 @@
@Test
public void testRuntimePaths() {
- Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
- .getRuntimePaths();
+ RuntimePath[] runtimePaths = RuntimeUIActivator.getRuntimePaths();
assertTrue(
"runtimePaths.size()\nExpected: 6\nWas: " + runtimePaths.size(),
- runtimePaths.size() == 6);
+ runtimePaths.length == 6);
}
@Test
public void testRuntimePathsExists() {
- Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
- .getRuntimePaths();
+ RuntimePath[] runtimePaths = RuntimeUIActivator.getRuntimePaths();
for (RuntimePath runtimePath:runtimePaths) {
String path = runtimePath.getPath();
File file = new File(path);
@@ -207,8 +204,7 @@
public void testServerDefinitions() {
List<RuntimeDefinition> serverDefinitions = RuntimeUIActivator
.getDefault().getServerDefinitions();
- Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
- .getRuntimePaths();
+ RuntimePath[] runtimePaths = RuntimeUIActivator.getRuntimePaths();
assertTrue("serverDefinitions.size()\nExpected: 6\nWas: "
+ serverDefinitions.size() +
"\nserverDefinitions: " + serverDefinitions +
More information about the jbosstools-commits
mailing list