Author: snjeza
Date: 2011-06-07 14:29:29 -0400 (Tue, 07 Jun 2011)
New Revision: 31881
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime.as.detector/src/org/jboss/tools/runtime/handlers/JBossASHandler.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.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/dialogs/EditRuntimePathDialog.java
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/RuntimePathEditingSupport.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/preferences/RuntimePreferencePage.java
trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionTest.java
Log:
JBIDE-9084 [runtimes] Adding duplicate folders should't be allowed
Modified:
trunk/runtime/plugins/org.jboss.tools.runtime.as.detector/src/org/jboss/tools/runtime/handlers/JBossASHandler.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime.as.detector/src/org/jboss/tools/runtime/handlers/JBossASHandler.java 2011-06-07
18:06:36 UTC (rev 31880)
+++
trunk/runtime/plugins/org.jboss.tools.runtime.as.detector/src/org/jboss/tools/runtime/handlers/JBossASHandler.java 2011-06-07
18:29:29 UTC (rev 31881)
@@ -318,6 +318,10 @@
// Don't create the driver a few times
return;
}
+ if (index == 8) {
+ // AS 7
+ return;
+ }
String driverPath;
try {
driverPath = new File(jbossASLocation +
JBOSS_AS_HSQL_DRIVER_LOCATION[index]).getCanonicalPath(); //$NON-NLS-1$
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 2011-06-07
18:06:36 UTC (rev 31880)
+++
trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/RuntimePath.java 2011-06-07
18:29:29 UTC (rev 31881)
@@ -94,4 +94,29 @@
this.timestamp = timestamp;
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((path == null) ? 0 : path.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ RuntimePath other = (RuntimePath) obj;
+ if (path == null) {
+ if (other.path != null)
+ return false;
+ } else if (!path.equals(other.path))
+ return false;
+ return true;
+ }
+
}
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 2011-06-07
18:06:36 UTC (rev 31880)
+++
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeScanner.java 2011-06-07
18:29:29 UTC (rev 31881)
@@ -11,6 +11,7 @@
package org.jboss.tools.runtime.ui;
import java.util.List;
+import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -67,7 +68,7 @@
}
private boolean runtimeExists(boolean firstStart, IProgressMonitor monitor) {
- List<RuntimePath> runtimePaths =
RuntimeUIActivator.getDefault().getRuntimePaths();
+ Set<RuntimePath> runtimePaths =
RuntimeUIActivator.getDefault().getRuntimePaths();
for (RuntimePath runtimePath:runtimePaths) {
if (!firstStart && !runtimePath.isScanOnEveryStartup()) {
continue;
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 2011-06-07
18:06:36 UTC (rev 31880)
+++
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/RuntimeUIActivator.java 2011-06-07
18:29:29 UTC (rev 31881)
@@ -18,6 +18,7 @@
import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -108,7 +109,7 @@
private static final String RUNTIME_PREFERENCES_VERSION = "2"; //$NON-NLS-1$
- private List<RuntimePath> runtimePaths = new ArrayList<RuntimePath>();
+ private Set<RuntimePath> runtimePaths = new HashSet<RuntimePath>();
private Set<IRuntimeDetector> runtimeDetectors;
@@ -161,7 +162,7 @@
RuntimeUIActivator.getDefault().getLog().log(status);
}
- public static CheckboxTreeViewer createRuntimeViewer(final List<RuntimePath>
runtimePaths2, Composite composite, int heightHint) {
+ public static CheckboxTreeViewer createRuntimeViewer(final Set<RuntimePath>
runtimePaths2, Composite composite, int heightHint) {
GridData gd;
CheckboxTreeViewer viewer = new CheckboxTreeViewer(composite, SWT.V_SCROLL
| SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
@@ -198,7 +199,7 @@
return viewer;
}
- public static void refreshRuntimes(Shell shell, final List<RuntimePath>
runtimePaths, final CheckboxTreeViewer viewer, boolean needRefresh, int heightHint) {
+ public static void refreshRuntimes(Shell shell, final Set<RuntimePath>
runtimePaths, final CheckboxTreeViewer viewer, boolean needRefresh, int heightHint) {
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
@@ -282,7 +283,7 @@
}
private void initRuntimePaths() throws WorkbenchException {
- runtimePaths = new ArrayList<RuntimePath>();
+ runtimePaths = new HashSet<RuntimePath>();
String runtimes = getPreferences().get(RUNTIME_PATHS, null);
if (runtimes == null || runtimes.isEmpty()) {
return;
@@ -354,7 +355,7 @@
private static IEclipsePreferences getPreferences() {
if (prefs == null) {
- prefs = new ConfigurationScope().getNode(PLUGIN_ID);
+ prefs = ConfigurationScope.INSTANCE.getNode(PLUGIN_ID);
}
return prefs;
}
@@ -418,13 +419,13 @@
node.putBoolean(ENABLED, serverDefinition.isEnabled());
}
- public List<RuntimePath> getRuntimePaths() {
+ public Set<RuntimePath> getRuntimePaths() {
if (runtimePaths == null) {
try {
initRuntimePaths();
} catch (WorkbenchException e) {
log(e);
- runtimePaths = new ArrayList<RuntimePath>();
+ runtimePaths = new HashSet<RuntimePath>();
}
}
return runtimePaths;
@@ -450,11 +451,11 @@
}
public void initDefaultRuntimePreferences() {
- runtimePaths = new ArrayList<RuntimePath>();
+ runtimePaths = new HashSet<RuntimePath>();
runtimeDetectors = RuntimeCoreActivator.getDeclaredRuntimeDetectors();
}
- public static void setTimestamp(List<RuntimePath> runtimePaths2) {
+ public static void setTimestamp(Set<RuntimePath> runtimePaths2) {
for (RuntimePath runtimePath : runtimePaths2) {
String path = runtimePath.getPath();
if (path != null && !path.isEmpty()) {
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 2011-06-07
18:06:36 UTC (rev 31880)
+++
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/EditRuntimePathDialog.java 2011-06-07
18:29:29 UTC (rev 31881)
@@ -11,8 +11,8 @@
package org.jboss.tools.runtime.ui.dialogs;
import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
@@ -44,7 +44,7 @@
public class EditRuntimePathDialog extends Dialog {
private RuntimePath runtimePath;
- private List<RuntimePath> runtimePaths;
+ private Set<RuntimePath> runtimePaths;
private CheckboxTreeViewer treeViewer;
public EditRuntimePathDialog(Shell parentShell, RuntimePath runtimePath) {
@@ -94,7 +94,7 @@
if (path == null) {
return;
}
- List<RuntimePath> runtimePaths2 = new ArrayList<RuntimePath>();
+ Set<RuntimePath> runtimePaths2 = new HashSet<RuntimePath>();
runtimePaths2.add(runtimePath);
RuntimeUIActivator.refreshRuntimes(getShell(), runtimePaths2, null, true, 15);
dialogSettings.put(RuntimeUIActivator.LASTPATH, path);
@@ -132,7 +132,7 @@
});
refreshButton.setEnabled( (new File(pathText.getText()).isDirectory()) );
- List<RuntimePath> runtimePaths = getRuntimePaths();
+ Set<RuntimePath> runtimePaths = getRuntimePaths();
treeViewer = RuntimeUIActivator.createRuntimeViewer(runtimePaths, contents, 100);
treeViewer.addCheckStateListener(new ICheckStateListener() {
@@ -145,9 +145,9 @@
return area;
}
- private List<RuntimePath> getRuntimePaths() {
+ private Set<RuntimePath> getRuntimePaths() {
if (runtimePaths == null) {
- runtimePaths = new ArrayList<RuntimePath>();
+ 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/RuntimePathEditingSupport.java
===================================================================
---
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/RuntimePathEditingSupport.java 2011-06-07
18:06:36 UTC (rev 31880)
+++
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/RuntimePathEditingSupport.java 2011-06-07
18:29:29 UTC (rev 31881)
@@ -48,6 +48,9 @@
@Override
protected boolean canEdit(Object element) {
+ if (this.column == 0) {
+ return false;
+ }
return true;
}
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 2011-06-07
18:06:36 UTC (rev 31880)
+++
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/dialogs/SearchRuntimePathDialog.java 2011-06-07
18:29:29 UTC (rev 31881)
@@ -12,6 +12,7 @@
import java.io.File;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -52,7 +53,7 @@
*/
public class SearchRuntimePathDialog extends ProgressMonitorDialog {
- private List<RuntimePath> runtimePaths = new ArrayList<RuntimePath>();
+ private Set<RuntimePath> runtimePaths = new HashSet<RuntimePath>();
private boolean running = true;
private CheckboxTreeViewer treeViewer;
private boolean canceled;
@@ -62,7 +63,7 @@
private Button hideCreatedRuntimes;
private int heightHint;
- public SearchRuntimePathDialog(Shell parent, List<RuntimePath> runtimePaths,
boolean needRefresh, int heightHint) {
+ public SearchRuntimePathDialog(Shell parent, Set<RuntimePath> runtimePaths,
boolean needRefresh, int heightHint) {
super(parent);
setShellStyle(SWT.CLOSE | SWT.MAX | SWT.TITLE | SWT.BORDER
| SWT.RESIZE | getDefaultOrientation());
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 2011-06-07
18:06:36 UTC (rev 31880)
+++
trunk/runtime/plugins/org.jboss.tools.runtime.ui/src/org/jboss/tools/runtime/ui/preferences/RuntimePreferencePage.java 2011-06-07
18:29:29 UTC (rev 31881)
@@ -11,8 +11,7 @@
package org.jboss.tools.runtime.ui.preferences;
import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -72,9 +71,6 @@
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.jboss.tools.runtime.core.model.IRuntimeDetector;
import org.jboss.tools.runtime.core.model.RuntimePath;
-import org.jboss.tools.runtime.core.model.ServerDefinition;
-import org.jboss.tools.runtime.ui.RuntimeContentProvider;
-import org.jboss.tools.runtime.ui.RuntimeLabelProvider;
import org.jboss.tools.runtime.ui.RuntimeUIActivator;
import org.jboss.tools.runtime.ui.dialogs.AutoResizeTableLayout;
import org.jboss.tools.runtime.ui.dialogs.EditRuntimePathDialog;
@@ -88,7 +84,7 @@
IWorkbenchPreferencePage {
public static String ID =
"org.jboss.tools.runtime.preferences.RuntimePreferencePage";
- private List<RuntimePath> runtimePaths = new ArrayList<RuntimePath>();
+ private Set<RuntimePath> runtimePaths = new HashSet<RuntimePath>();
private Image checkboxOn;
private Image checkboxOff;
private Image errorIcon;
@@ -129,82 +125,11 @@
Group detectorGroup = createGroup(composite,1);
detectorGroup.setText("Available runtime detectors");
detectorViewer = createDetectorViewer(detectorGroup);
-
-// Group runtimeDescriptionGroup = createGroup(composite,1);
-// Label runtimeDescription = new Label(runtimeDescriptionGroup, SWT.NONE);
-// runtimeDescription.setText("Runtimes found at the selected path.\n" +
-// "Remove the check mark for any runtimes you do not want identified.");
-// Group runtimeGroup = createGroup(composite,1);
-// final TableViewer runtimesViewer = createRuntimesViewer(runtimeGroup);
-// runtimePathViewer.addSelectionChangedListener(new ISelectionChangedListener() {
-//
-// @Override
-// public void selectionChanged(SelectionChangedEvent event) {
-// runtimesViewer.setInput(getServerDefinitions());
-// }
-// });
-
+
Dialog.applyDialogFont(composite);
return composite;
}
- private TableViewer createRuntimesViewer(Composite parent) {
- CheckboxTableViewer tableViewer = CheckboxTableViewer.newCheckList(parent,
SWT.V_SCROLL
- | SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
- Table table = tableViewer.getTable();
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.heightHint = 100;
- table.setLayoutData(gd);
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
-
- String[] columnNames = new String[] { "Name", "Version",
"Type", "Location", "Description"};
- int[] columnWidths = new int[] { 120, 50, 50, 150, 150};
-
- for (int i = 0; i < columnNames.length; i++) {
- TableColumn tc = new TableColumn(table, SWT.LEFT);
- tc.setText(columnNames[i]);
- tc.setWidth(columnWidths[i]);
- }
-
- tableViewer.setLabelProvider(new RuntimeLabelProvider());
- final List<ServerDefinition> serverDefinitions = getServerDefinitions();
- tableViewer.setContentProvider(new RuntimeContentProvider(serverDefinitions));
- tableViewer.setInput(serverDefinitions);
- for (ServerDefinition definition:serverDefinitions) {
- tableViewer.setChecked(definition, definition.isEnabled());
- }
- tableViewer.addCheckStateListener(new ICheckStateListener() {
-
- public void checkStateChanged(CheckStateChangedEvent event) {
- ServerDefinition definition = (ServerDefinition) event.getElement();
- definition.setEnabled(!definition.isEnabled());
-// boolean enableOk = false;
-// for (ServerDefinition serverDefinition:serverDefinitions) {
-// if (serverDefinition.isEnabled()) {
-// enableOk = true;
-// }
-// }
- }
- });
- return tableViewer;
- }
-
- private List<ServerDefinition> getServerDefinitions() {
- List<ServerDefinition> serverDefinitions = new
ArrayList<ServerDefinition>();
- if (runtimePathViewer == null) {
- return serverDefinitions;
- }
- ISelection selection = runtimePathViewer.getSelection();
- if (selection instanceof IStructuredSelection) {
- Object object = ((IStructuredSelection)selection).getFirstElement();
- if (object instanceof RuntimePath) {
- serverDefinitions = ((RuntimePath)object).getServerDefinitions();
- }
- }
- return serverDefinitions;
- }
-
private Group createGroup(Composite composite, int column) {
GridLayout layout;
Group group = new Group(composite, SWT.NONE);
@@ -376,8 +301,12 @@
}
dialogSettings.put(RuntimeUIActivator.LASTPATH, path);
RuntimePath runtimePath = new RuntimePath(path);
- runtimePaths.add(runtimePath);
- List<RuntimePath> runtimePaths2 = new ArrayList<RuntimePath>();
+ 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();
@@ -411,6 +340,13 @@
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);
Modified:
trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionTest.java
===================================================================
---
trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionTest.java 2011-06-07
18:06:36 UTC (rev 31880)
+++
trunk/runtime/tests/org.jboss.tools.runtime.test/src/org/jboss/tools/runtime/test/RuntimeDetectionTest.java 2011-06-07
18:29:29 UTC (rev 31881)
@@ -75,7 +75,7 @@
}
private static void addRuntimePaths() {
- List<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
+ Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
.getRuntimePaths();
String[] paths = { IRuntimeDetectionConstants.JBOSS_42_HOME,
IRuntimeDetectionConstants.JBOSS_51_HOME,
@@ -102,7 +102,7 @@
private static void createRuntimes() {
JBossRuntimeLocator locator = new JBossRuntimeLocator();
- List<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
+ Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
.getRuntimePaths();
for (RuntimePath runtimePath : runtimePaths) {
List<ServerDefinition> serverDefinitions = locator
@@ -134,7 +134,7 @@
@Test
public void testRuntimePaths() {
- List<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
+ Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
.getRuntimePaths();
assertTrue(
"runtimePaths.size()\nExpected: 6\nWas: " + runtimePaths.size(),
@@ -143,7 +143,7 @@
@Test
public void testRuntimePathsExists() {
- List<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
+ Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
.getRuntimePaths();
for (RuntimePath runtimePath:runtimePaths) {
String path = runtimePath.getPath();
@@ -207,7 +207,7 @@
public void testServerDefinitions() {
List<ServerDefinition> serverDefinitions = RuntimeUIActivator
.getDefault().getServerDefinitions();
- List<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
+ Set<RuntimePath> runtimePaths = RuntimeUIActivator.getDefault()
.getRuntimePaths();
assertTrue("serverDefinitions.size()\nExpected: 6\nWas: "
+ serverDefinitions.size() +