summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Aubry2012-10-16 10:49:27 (EDT)
committerSimon Bernard2012-10-16 11:29:56 (EDT)
commit20acf16f0f2e832eb273432b06dc4561edebc392 (patch)
tree04a9f54822580fcfe16b4d3904bd891c087a4695
parent92db1d35e1ed0c5556c9d53c3ceb9924c35ef8e9 (diff)
downloadorg.eclipse.koneki.ldt-20acf16f0f2e832eb273432b06dc4561edebc392.zip
org.eclipse.koneki.ldt-20acf16f0f2e832eb273432b06dc4561edebc392.tar.gz
org.eclipse.koneki.ldt-20acf16f0f2e832eb273432b06dc4561edebc392.tar.bz2
Bug 392078 - Be able to hide embedded Execution Environment using
activity eclipse mechanism
-rw-r--r--plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/LuaExecutionEnvironmentUIManager.java103
-rw-r--r--plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/buildpath/LuaExecutionEnvironmentWizardPage.java5
-rw-r--r--plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/preferences/LuaExecutionEnvironmentPreferencePage.java39
-rw-r--r--plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/wizards/pages/LuaExecutionEnvironmentGroup.java4
-rw-r--r--plugins/org.eclipse.koneki.ldt/src/org/eclipse/koneki/ldt/core/internal/buildpath/LuaExecutionEnvironmentManager.java4
5 files changed, 147 insertions, 8 deletions
diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/LuaExecutionEnvironmentUIManager.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/LuaExecutionEnvironmentUIManager.java
new file mode 100644
index 0000000..fffc6fd
--- /dev/null
+++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/LuaExecutionEnvironmentUIManager.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Sierra Wireless and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sierra Wireless - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.koneki.ldt.ui;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.koneki.ldt.core.internal.buildpath.LuaExecutionEnvironment;
+import org.eclipse.koneki.ldt.core.internal.buildpath.LuaExecutionEnvironmentManager;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.activities.IActivity;
+import org.eclipse.ui.activities.IActivityListener;
+import org.eclipse.ui.activities.IActivityManager;
+import org.eclipse.ui.activities.IActivityPatternBinding;
+
+/**
+ * A class similar to LuaExecutionEnvironmentManager but take in account activities enable/disabled EEs
+ *
+ * Only activities with following format of binding pattern are take in account:
+ * <code><plugin id>/org.eclipse.koneki.ldt.executionEnvironment.<EE's id>-<EE's version></code>
+ */
+public class LuaExecutionEnvironmentUIManager {
+
+ public static final String EE_EXTENTION_POINT_ID = "org.eclipse.koneki.ldt.executionEnvironment"; //$NON-NLS-1$
+
+ /**
+ * List all the installed and contributed activities enabled EEs.
+ */
+ public static List<LuaExecutionEnvironment> getAvailableExecutionEnvironments() {
+
+ List<LuaExecutionEnvironment> executionEnvironments = LuaExecutionEnvironmentManager.getAvailableExecutionEnvironments();
+ List<LuaExecutionEnvironment> newExecutionEnvironments = new ArrayList<LuaExecutionEnvironment>();
+ newExecutionEnvironments.addAll(executionEnvironments);
+
+ IActivityManager activityManager = PlatformUI.getWorkbench().getActivitySupport().getActivityManager();
+
+ // For all activities
+ @SuppressWarnings("unchecked")
+ Set<String> activities = activityManager.getDefinedActivityIds();
+ for (String activityId : activities) {
+ IActivity activity = activityManager.getActivity(activityId);
+
+ @SuppressWarnings("unchecked")
+ Set<IActivityPatternBinding> bindings = activity.getActivityPatternBindings();
+
+ if (!activity.isEnabled()) {
+ // For all binding witch contains the EE extension point id
+ for (IActivityPatternBinding binding : bindings) {
+ if (binding.getString().contains(EE_EXTENTION_POINT_ID)) {
+
+ // Remove all the EE with the same id and version
+ for (LuaExecutionEnvironment luaExecutionEnvironment : executionEnvironments) {
+ if (luaExecutionEnvironment.isEmbedded() && binding.getString().endsWith(luaExecutionEnvironment.getEEIdentifier())) {
+ newExecutionEnvironments.remove(luaExecutionEnvironment);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return newExecutionEnvironments;
+ }
+
+ public static Set<IActivity> addListenerToEERelatedActivity(IActivityListener activityListener) {
+ HashSet<IActivity> activitiesWatched = new HashSet<IActivity>();
+
+ // Listen to all activities than can hide EE to refresh the UI
+ IActivityManager activityManager = PlatformUI.getWorkbench().getActivitySupport().getActivityManager();
+
+ // For all activities
+ @SuppressWarnings("unchecked")
+ Set<String> activities = activityManager.getDefinedActivityIds();
+ for (String activityId : activities) {
+ IActivity activity = activityManager.getActivity(activityId);
+
+ @SuppressWarnings("unchecked")
+ Set<IActivityPatternBinding> bindings = activity.getActivityPatternBindings();
+
+ // For all binding witch contains the EE extension point id
+ for (IActivityPatternBinding binding : bindings) {
+ if (binding.getString().contains(LuaExecutionEnvironmentUIManager.EE_EXTENTION_POINT_ID)) {
+
+ // save activities to watch to be able to unregister listeners
+ activitiesWatched.add(activity);
+
+ activity.addActivityListener(activityListener);
+ }
+ }
+ }
+ return activitiesWatched;
+ }
+}
diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/buildpath/LuaExecutionEnvironmentWizardPage.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/buildpath/LuaExecutionEnvironmentWizardPage.java
index eb3ca30..4abb602 100644
--- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/buildpath/LuaExecutionEnvironmentWizardPage.java
+++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/buildpath/LuaExecutionEnvironmentWizardPage.java
@@ -21,7 +21,7 @@ import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.koneki.ldt.core.internal.buildpath.LuaExecutionEnvironment;
import org.eclipse.koneki.ldt.core.internal.buildpath.LuaExecutionEnvironmentBuildpathUtil;
import org.eclipse.koneki.ldt.core.internal.buildpath.LuaExecutionEnvironmentConstants;
-import org.eclipse.koneki.ldt.core.internal.buildpath.LuaExecutionEnvironmentManager;
+import org.eclipse.koneki.ldt.ui.LuaExecutionEnvironmentUIManager;
import org.eclipse.koneki.ldt.ui.SWTUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
@@ -135,7 +135,7 @@ public class LuaExecutionEnvironmentWizardPage extends NewElementWizardPage impl
}
// get new input
- final List<LuaExecutionEnvironment> newInput = LuaExecutionEnvironmentManager.getAvailableExecutionEnvironments();
+ final List<LuaExecutionEnvironment> newInput = LuaExecutionEnvironmentUIManager.getAvailableExecutionEnvironments();
eeTreeViewer.setInput(newInput);
// try to guess the better new selection
@@ -155,7 +155,6 @@ public class LuaExecutionEnvironmentWizardPage extends NewElementWizardPage impl
}
}
}
-
}
private LuaExecutionEnvironment getSelectedExecutionEnvironment() {
diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/preferences/LuaExecutionEnvironmentPreferencePage.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/preferences/LuaExecutionEnvironmentPreferencePage.java
index be21fbe..1cdad8f 100644
--- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/preferences/LuaExecutionEnvironmentPreferencePage.java
+++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/preferences/LuaExecutionEnvironmentPreferencePage.java
@@ -12,7 +12,9 @@ package org.eclipse.koneki.ldt.ui.internal.preferences;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.ErrorDialog;
@@ -31,6 +33,7 @@ import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.koneki.ldt.core.internal.buildpath.LuaExecutionEnvironment;
import org.eclipse.koneki.ldt.core.internal.buildpath.LuaExecutionEnvironmentConstants;
import org.eclipse.koneki.ldt.core.internal.buildpath.LuaExecutionEnvironmentManager;
+import org.eclipse.koneki.ldt.ui.LuaExecutionEnvironmentUIManager;
import org.eclipse.koneki.ldt.ui.SWTUtil;
import org.eclipse.koneki.ldt.ui.internal.Activator;
import org.eclipse.koneki.ldt.ui.internal.buildpath.LuaExecutionEnvironmentContentProvider;
@@ -50,14 +53,27 @@ import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.activities.ActivityEvent;
+import org.eclipse.ui.activities.IActivity;
+import org.eclipse.ui.activities.IActivityListener;
public class LuaExecutionEnvironmentPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
private static final String AVAILABLE_EXECUTION_ENVIRONEMENT_URL = "http://wiki.eclipse.org/Koneki/LDT/User_Area/Available_Execution_Environments"; //$NON-NLS-1$
-
+
private TreeViewer eeTreeViewer;
private Button removeButton;
+ private Set<IActivity> activitiesWatched = new HashSet<IActivity>();
+ private IActivityListener activityListener = new IActivityListener() {
+ @Override
+ public void activityChanged(ActivityEvent activityEvent) {
+ if (activityEvent.hasEnabledChanged()) {
+ initializePage();
+ }
+ }
+ };
+
public LuaExecutionEnvironmentPreferencePage() {
setDescription(Messages.LuaExecutionEnvironmentPreferencePageTitle);
noDefaultAndApplyButton();
@@ -147,6 +163,9 @@ public class LuaExecutionEnvironmentPreferencePage extends PreferencePage implem
}
});
+ // add a listener to activities which can hide EE to refresh the UI
+ activitiesWatched = LuaExecutionEnvironmentUIManager.addListenerToEERelatedActivity(activityListener);
+
// ----------------
// Initialize UI
initializePage();
@@ -232,13 +251,27 @@ public class LuaExecutionEnvironmentPreferencePage extends PreferencePage implem
}
private void initializePage() {
- if (eeTreeViewer == null)
+ if (eeTreeViewer == null || eeTreeViewer.getControl().isDisposed())
return;
// Refresh list
- eeTreeViewer.setInput(LuaExecutionEnvironmentManager.getAvailableExecutionEnvironments());
+ eeTreeViewer.setInput(LuaExecutionEnvironmentUIManager.getAvailableExecutionEnvironments());
// As list is refreshed, they is no selection
refreshRemoveButton();
}
+
+ /**
+ * @see org.eclipse.jface.dialogs.DialogPage#dispose()
+ */
+ @Override
+ public void dispose() {
+ // dispose the listener watching something not build in this page
+ for (IActivity activity : activitiesWatched) {
+ activity.removeActivityListener(activityListener);
+ }
+
+ super.dispose();
+
+ }
}
diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/wizards/pages/LuaExecutionEnvironmentGroup.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/wizards/pages/LuaExecutionEnvironmentGroup.java
index 9257fd3..f69e6f1 100644
--- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/wizards/pages/LuaExecutionEnvironmentGroup.java
+++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/wizards/pages/LuaExecutionEnvironmentGroup.java
@@ -22,7 +22,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.koneki.ldt.core.internal.buildpath.LuaExecutionEnvironment;
import org.eclipse.koneki.ldt.core.internal.buildpath.LuaExecutionEnvironmentConstants;
-import org.eclipse.koneki.ldt.core.internal.buildpath.LuaExecutionEnvironmentManager;
+import org.eclipse.koneki.ldt.ui.LuaExecutionEnvironmentUIManager;
import org.eclipse.koneki.ldt.ui.internal.buildpath.LuaExecutionEnvironmentContentProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -149,7 +149,7 @@ public class LuaExecutionEnvironmentGroup extends Observable {
private void updateExecutionEnvironmentList() {
if (installedEEsComboViewer != null && eeButton != null && noEEButton != null) {
- final List<LuaExecutionEnvironment> installedExecutionEnvironments = LuaExecutionEnvironmentManager.getAvailableExecutionEnvironments();
+ final List<LuaExecutionEnvironment> installedExecutionEnvironments = LuaExecutionEnvironmentUIManager.getAvailableExecutionEnvironments();
installedEEsComboViewer.setInput(installedExecutionEnvironments);
// Select first execution environment when available
diff --git a/plugins/org.eclipse.koneki.ldt/src/org/eclipse/koneki/ldt/core/internal/buildpath/LuaExecutionEnvironmentManager.java b/plugins/org.eclipse.koneki.ldt/src/org/eclipse/koneki/ldt/core/internal/buildpath/LuaExecutionEnvironmentManager.java
index f3a1c0c..555a7d6 100644
--- a/plugins/org.eclipse.koneki.ldt/src/org/eclipse/koneki/ldt/core/internal/buildpath/LuaExecutionEnvironmentManager.java
+++ b/plugins/org.eclipse.koneki.ldt/src/org/eclipse/koneki/ldt/core/internal/buildpath/LuaExecutionEnvironmentManager.java
@@ -389,6 +389,10 @@ public final class LuaExecutionEnvironmentManager {
return result;
}
+ /**
+ * List all the installed and contributed EEs. To have only activities enabled EE see LuaExecutionEnvironmentUIManager
+ *
+ */
public static List<LuaExecutionEnvironment> getAvailableExecutionEnvironments() {
List<LuaExecutionEnvironment> availableExecutionEnvironments = getInstalledExecutionEnvironments();