Open portal in new and reset carbide perspective and if left open
authordadubrow
Tue, 14 Sep 2010 11:40:12 -0500
changeset 2000 9078a58d3988
parent 1999 8fef5b8ecdd8
child 2001 75d787292eea
Open portal in new and reset carbide perspective and if left open
core/com.nokia.carbide.discovery.ui/plugin.xml
core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/PortalEditor.java
project/com.nokia.carbide.cpp.project.ui/src/com/nokia/carbide/cpp/internal/project/ui/perspective/CarbideCppPerspectiveFactory.java
--- a/core/com.nokia.carbide.discovery.ui/plugin.xml	Tue Sep 14 10:19:24 2010 -0500
+++ b/core/com.nokia.carbide.discovery.ui/plugin.xml	Tue Sep 14 11:40:12 2010 -0500
@@ -170,5 +170,12 @@
          </description>
       </wizard>
    </extension>
+   <extension
+         point="org.eclipse.ui.elementFactories">
+      <factory
+            class="com.nokia.carbide.internal.discovery.ui.editor.PortalEditor"
+            id="com.nokia.carbide.discovery.ui.portalEditorFactory">
+      </factory>
+   </extension>
 
 </plugin>
--- a/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/PortalEditor.java	Tue Sep 14 10:19:24 2010 -0500
+++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/editor/PortalEditor.java	Tue Sep 14 11:40:12 2010 -0500
@@ -25,6 +25,7 @@
 import java.util.Map;
 
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.Platform;
@@ -46,6 +47,8 @@
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
 import org.eclipse.ui.IPersistableElement;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
@@ -60,8 +63,50 @@
 import com.nokia.cpp.internal.api.utils.core.Pair;
 import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
 
-public class PortalEditor extends EditorPart implements IPortalEditor {
+public class PortalEditor extends EditorPart implements IPortalEditor, IElementFactory {
 	
+	private static final class PortalEditorInput implements IEditorInput {
+		@SuppressWarnings("rawtypes")
+		@Override
+		public Object getAdapter(Class adapter) {
+			return null;
+		}
+
+		@Override
+		public String getToolTipText() {
+			return getName();
+		}
+
+		@Override
+		public IPersistableElement getPersistable() {
+			return new IPersistableElement() {
+				@Override
+				public void saveState(IMemento memento) {
+				}
+				
+				@Override
+				public String getFactoryId() {
+					return "com.nokia.carbide.discovery.ui.portalEditorFactory"; //$NON-NLS-1$
+				}
+			};
+		}
+
+		@Override
+		public String getName() {
+			return Messages.PortalEditor_Name;
+		}
+
+		@Override
+		public ImageDescriptor getImageDescriptor() {
+			return null;
+		}
+
+		@Override
+		public boolean exists() {
+			return true;
+		}
+	}
+
 	class LayerExtension {
 		public LayerExtension(IPortalPageLayer layer, String title, int order) {
 			this.layer = layer;
@@ -257,47 +302,22 @@
 	}
 	
 	public static void openPortal() {
-		try {
-			WorkbenchUtils.openEditor(getInput(), ID);
-		} catch (PartInitException e) {
-			Activator.logError(Messages.PortalEditor_PageOpenError, e);
-		}
+		Display.getDefault().asyncExec(new Runnable() {
+			@Override
+			public void run() {
+				try {
+					if (PlatformUI.isWorkbenchRunning())
+						WorkbenchUtils.openEditor(getInput(), ID);
+				} catch (PartInitException e) {
+					Activator.logError(Messages.PortalEditor_PageOpenError, e);
+				}
+			}
+		});
 	}
-
+	
 	private static IEditorInput getInput() {
 		if (input == null) {
-			input = new IEditorInput() {
-				@SuppressWarnings("rawtypes")
-				@Override
-				public Object getAdapter(Class adapter) {
-					return null;
-				}
-				
-				@Override
-				public String getToolTipText() {
-					return getName();
-				}
-				
-				@Override
-				public IPersistableElement getPersistable() {
-					return null;
-				}
-				
-				@Override
-				public String getName() {
-					return Messages.PortalEditor_Name;
-				}
-				
-				@Override
-				public ImageDescriptor getImageDescriptor() {
-					return null;
-				}
-				
-				@Override
-				public boolean exists() {
-					return false;
-				}
-			};
+			input = new PortalEditorInput();
 		}
 			
 		return input;
@@ -341,4 +361,9 @@
 		return this;
 	}
 
+	@Override
+	public IAdaptable createElement(IMemento memento) {
+		return new PortalEditorInput();
+	}
+
 }
--- a/project/com.nokia.carbide.cpp.project.ui/src/com/nokia/carbide/cpp/internal/project/ui/perspective/CarbideCppPerspectiveFactory.java	Tue Sep 14 10:19:24 2010 -0500
+++ b/project/com.nokia.carbide.cpp.project.ui/src/com/nokia/carbide/cpp/internal/project/ui/perspective/CarbideCppPerspectiveFactory.java	Tue Sep 14 11:40:12 2010 -0500
@@ -18,10 +18,16 @@
 
 import org.eclipse.cdt.internal.ui.wizards.CWizardRegistry;
 import org.eclipse.cdt.ui.CUIPlugin;
-import org.eclipse.ui.*;
+import org.eclipse.ui.IFolderLayout;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IPerspectiveFactory;
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.console.IConsoleConstants;
+import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.navigator.resources.ProjectExplorer;
 
+import com.nokia.carbide.cpp.internal.project.ui.ProjectUIPlugin;
+
 public class CarbideCppPerspectiveFactory implements IPerspectiveFactory {
 		
 	private static final String SYMBIAN_PROJECT_NAVIGATOR_VIEW_ID = 
@@ -83,6 +89,14 @@
 		layout.addShowInPart(ProjectExplorer.VIEW_ID);
 		
 		addCDTWizardShortcutIdsToLayout(layout);
+		
+		IHandlerService handlerService = 
+			(IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
+        try {
+			handlerService.executeCommand("com.nokia.carbide.discovery.commands.launch", null); //$NON-NLS-1$
+        } catch (Exception e) {
+			ProjectUIPlugin.log(e);
+		}
 	}
 	
 	@SuppressWarnings("restriction")