[jbosstools-commits] JBoss Tools SVN: r43576 - trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Tue Sep 11 03:21:41 EDT 2012
Author: rob.stryker at jboss.com
Date: 2012-09-11 03:21:40 -0400 (Tue, 11 Sep 2012)
New Revision: 43576
Added:
trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/RuntimeModel.java
Log:
JBIDE-12549 to trunk missing file
Added: trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/RuntimeModel.java
===================================================================
--- trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/RuntimeModel.java (rev 0)
+++ trunk/runtime/plugins/org.jboss.tools.runtime.core/src/org/jboss/tools/runtime/core/model/RuntimeModel.java 2012-09-11 07:21:40 UTC (rev 43576)
@@ -0,0 +1,98 @@
+package org.jboss.tools.runtime.core.model;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.jboss.tools.runtime.core.RuntimeCoreActivator;
+import org.jboss.tools.runtime.core.util.RuntimePathPreferenceIO;
+
+public class RuntimeModel {
+ public static final String RUNTIME_PATHS = "runtimePaths";
+
+ private ListenerList runtimePathChangeChangeListeners;
+ private Set<RuntimePath> runtimePaths;
+ private IEclipsePreferences preferences;
+
+ public RuntimeModel() {
+ runtimePaths = new HashSet<RuntimePath>();
+ }
+
+ public RuntimeModel(IEclipsePreferences preferences) {
+ this.preferences = preferences;
+ reloadRuntimePathsFromPreferences();
+ }
+
+ public void reloadRuntimePathsFromPreferences() {
+ String runtimes = preferences.get(RUNTIME_PATHS, null);
+ if (runtimes != null && !runtimes.isEmpty()) {
+ runtimePaths = RuntimePathPreferenceIO.loadRuntimePathsFromPreferenceString(runtimes);
+ } else {
+ runtimePaths = new HashSet<RuntimePath>();
+ }
+ fireRuntimePathsChanged();
+ }
+
+ public void saveRuntimePaths() {
+ if (runtimePaths == null || preferences == null)
+ return;
+
+ try {
+ String runtimes = RuntimePathPreferenceIO.getPreferenceOutputString(runtimePaths);
+ preferences.put(RUNTIME_PATHS, runtimes);
+ preferences.flush();
+ fireRuntimePathsChanged();
+ } catch (Exception e) {
+ RuntimeCoreActivator.getDefault().logError(e);
+ }
+ }
+
+ public synchronized void setRuntimePaths(RuntimePath[] set) {
+ if( set == null ) {
+ reloadRuntimePathsFromPreferences();
+ } else {
+ HashSet<RuntimePath> s = new HashSet<RuntimePath>();
+ s.addAll(Arrays.asList(set));
+ runtimePaths = s;
+ saveRuntimePaths();
+ }
+ }
+
+ public void addRuntimePath(RuntimePath path) {
+ runtimePaths.add(path);
+ saveRuntimePaths();
+ }
+ public void removeRuntimePath(RuntimePath path) {
+ runtimePaths.remove(path);
+ saveRuntimePaths();
+ }
+
+ public synchronized RuntimePath[] getRuntimePaths() {
+ return (RuntimePath[]) runtimePaths.toArray(new RuntimePath[runtimePaths.size()]);
+ }
+
+ public synchronized void addRuntimePathChangeListener(IRuntimePathChangeListener listener) {
+ if (runtimePathChangeChangeListeners == null)
+ runtimePathChangeChangeListeners = new ListenerList();
+ runtimePathChangeChangeListeners.add(listener);
+ }
+
+ public synchronized void removeRuntimePathChangeListener(IRuntimePathChangeListener listener) {
+ if (runtimePathChangeChangeListeners == null)
+ return;
+ runtimePathChangeChangeListeners.remove(listener);
+ }
+
+ private void fireRuntimePathsChanged() {
+ if (runtimePathChangeChangeListeners != null) {
+ Object[] listeners = runtimePathChangeChangeListeners.getListeners();
+ for (Object listener:listeners ) {
+ IRuntimePathChangeListener runtimePathChangeChangeListener = (IRuntimePathChangeListener) listener;
+ runtimePathChangeChangeListener.changed();
+ }
+ }
+ }
+
+}
More information about the jbosstools-commits
mailing list