Permalink
Browse files

Add New Server actions.

  • Loading branch information...
angelozerr committed Sep 10, 2012
1 parent 1cde935 commit 6488ea0c94f78ee0ec25b2f506174d6598c54b92
@@ -44,6 +44,11 @@
<extension
point="org.eclipse.ui.commands">
+ <command
+ defaultHandler="fr.opensagres.nosql.ide.mongodb.ui.internal.handlers.NewServerWizardHandler"
+ id="fr.opensagres.nosql.ide.mongodb.ui.handlers.NewServerWizardHandler"
+ name="New server">
+ </command>
<command
defaultHandler="fr.opensagres.nosql.ide.mongodb.ui.internal.handlers.OpenServerEditorHandler"
id="fr.opensagres.nosql.ide.mongodb.ui.handlers.OpenServerEditorHandler"
@@ -73,7 +78,7 @@
defaultHandler="fr.opensagres.nosql.ide.mongodb.ui.internal.handlers.OpenDocumentEditorHandler"
id="fr.opensagres.nosql.ide.mongodb.ui.handlers.OpenDocumentEditorHandler"
name="Edit server">
- </command>
+ </command>
</extension>
<extension
@@ -1,8 +1,10 @@
package fr.opensagres.nosql.ide.mongodb.ui.internal.extension;
import fr.opensagres.nosql.ide.core.extensions.ICommandIdProvider;
+import fr.opensagres.nosql.ide.core.extensions.IServerType;
import fr.opensagres.nosql.ide.core.model.ITreeSimpleNode;
import fr.opensagres.nosql.ide.core.model.NodeTypeConstants;
+import fr.opensagres.nosql.ide.mongodb.ui.internal.handlers.NewServerWizardHandler;
import fr.opensagres.nosql.ide.mongodb.ui.internal.handlers.OpenCollectionEditorHandler;
import fr.opensagres.nosql.ide.mongodb.ui.internal.handlers.OpenDatabaseEditorHandler;
import fr.opensagres.nosql.ide.mongodb.ui.internal.handlers.OpenDocumentEditorHandler;
@@ -13,6 +15,15 @@
public class MongoCommandIdProvider extends AbstractCommandIdProvider {
+ @Override
+ protected String getServerTypeCommandId(int type, IServerType element) {
+ switch (type) {
+ case ICommandIdProvider.OPEN_NEW_WIZARD:
+ return NewServerWizardHandler.ID;
+ }
+ return null;
+ }
+
@Override
protected String getCommmandId(int type, ITreeSimpleNode element) {
switch (element.getType()) {
@@ -0,0 +1,21 @@
+package fr.opensagres.nosql.ide.mongodb.ui.internal.handlers;
+
+import org.eclipse.core.commands.ExecutionEvent;
+
+import fr.opensagres.nosql.ide.mongodb.ui.wizards.server.NewServerWizard;
+import fr.opensagres.nosql.ide.ui.handlers.ContextHandlerEvent;
+import fr.opensagres.nosql.ide.ui.handlers.OpenWizardHandler;
+import fr.opensagres.nosql.ide.ui.wizards.AbstractWizard;
+
+public class NewServerWizardHandler extends OpenWizardHandler {
+
+ public static final String ID = "fr.opensagres.nosql.ide.mongodb.ui.handlers.NewServerWizardHandler";
+
+ @Override
+ protected AbstractWizard createWizard(ExecutionEvent event,
+ ContextHandlerEvent contextEvent) {
+ NewServerWizard wizard = new NewServerWizard();
+ return wizard;
+ }
+
+}
@@ -25,4 +25,21 @@
</wizard>
</extension>
+ <extension
+ point="fr.opensagres.nosql.ide.core.commandIdProviders">
+ <commandIdProvider
+ class="fr.opensagres.nosql.ide.orientdb.ui.internal.extensions.OrientCommandIdProvider"
+ serverType="fr.opensagres.nosql.ide.orientdb.core">
+ </commandIdProvider>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ defaultHandler="fr.opensagres.nosql.ide.orientdb.ui.internal.handlers.NewServerWizardHandler"
+ id="fr.opensagres.nosql.ide.orientdb.ui.handlers.NewServerWizardHandler"
+ name="New server">
+ </command>
+ </extension>
+
</plugin>
@@ -0,0 +1,24 @@
+package fr.opensagres.nosql.ide.orientdb.ui.internal.extensions;
+
+import fr.opensagres.nosql.ide.core.extensions.ICommandIdProvider;
+import fr.opensagres.nosql.ide.core.extensions.IServerType;
+import fr.opensagres.nosql.ide.core.model.ITreeSimpleNode;
+import fr.opensagres.nosql.ide.orientdb.ui.internal.handlers.NewServerWizardHandler;
+import fr.opensagres.nosql.ide.ui.extensions.AbstractCommandIdProvider;
+
+public class OrientCommandIdProvider extends AbstractCommandIdProvider {
+
+ @Override
+ protected String getServerTypeCommandId(int type, IServerType element) {
+ switch (type) {
+ case ICommandIdProvider.OPEN_NEW_WIZARD:
+ return NewServerWizardHandler.ID;
+ }
+ return null;
+ }
+
+ @Override
+ protected String getCommmandId(int type, ITreeSimpleNode element) {
+ return null;
+ }
+}
@@ -0,0 +1,21 @@
+package fr.opensagres.nosql.ide.orientdb.ui.internal.handlers;
+
+import org.eclipse.core.commands.ExecutionEvent;
+
+import fr.opensagres.nosql.ide.orientdb.ui.wizards.server.NewServerWizard;
+import fr.opensagres.nosql.ide.ui.handlers.ContextHandlerEvent;
+import fr.opensagres.nosql.ide.ui.handlers.OpenWizardHandler;
+import fr.opensagres.nosql.ide.ui.wizards.AbstractWizard;
+
+public class NewServerWizardHandler extends OpenWizardHandler {
+
+ public static final String ID = "fr.opensagres.nosql.ide.orientdb.ui.handlers.NewServerWizardHandler";
+
+ @Override
+ protected AbstractWizard createWizard(ExecutionEvent event,
+ ContextHandlerEvent contextEvent) {
+ NewServerWizard wizard = new NewServerWizard();
+ return wizard;
+ }
+
+}
@@ -1,6 +1,7 @@
package fr.opensagres.nosql.ide.ui.extensions;
import fr.opensagres.nosql.ide.core.extensions.ICommandIdProvider;
+import fr.opensagres.nosql.ide.core.extensions.IServerType;
import fr.opensagres.nosql.ide.core.model.ITreeSimpleNode;
import fr.opensagres.nosql.ide.core.model.NodeTypeConstants;
import fr.opensagres.nosql.ide.core.utils.StringUtils;
@@ -9,7 +10,9 @@
public abstract class AbstractCommandIdProvider implements ICommandIdProvider {
public String getCommmandId(int type, Object element) {
- if (element instanceof ITreeSimpleNode) {
+ if (element instanceof IServerType) {
+ return getServerTypeCommandId(type, (IServerType) element);
+ } else if (element instanceof ITreeSimpleNode) {
String commandId = getCommmandId(type, (ITreeSimpleNode) element);
if (StringUtils.isNotEmpty(commandId)) {
return commandId;
@@ -19,10 +22,13 @@ public String getCommmandId(int type, Object element) {
return null;
}
+ protected abstract String getServerTypeCommandId(int type,
+ IServerType element);
+
private String getGenericCommandId(int type, ITreeSimpleNode element) {
switch (element.getType()) {
case NodeTypeConstants.Server:
- switch(type) {
+ switch (type) {
case OPEN_NEW_WIZARD:
return NewDatabaseWizardHandler.ID;
}
@@ -54,6 +54,9 @@ protected String getCommandId(Object obj) {
}
protected IServerType getServerType(Object obj) {
+ if (obj instanceof IServerType) {
+ return (IServerType) obj;
+ }
if (obj instanceof ITreeSimpleNode) {
return ((ITreeSimpleNode) obj).getServer().getServerType();
}
@@ -0,0 +1,18 @@
+package fr.opensagres.nosql.ide.ui.internal.actions.servers;
+
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.services.IServiceLocator;
+
+import fr.opensagres.nosql.ide.core.extensions.ICommandIdProvider;
+import fr.opensagres.nosql.ide.ui.internal.Messages;
+import fr.opensagres.nosql.ide.ui.internal.actions.AbstractCommandAction;
+
+public class NewServerAction extends AbstractCommandAction {
+
+ public NewServerAction(ISelectionProvider provider,
+ IServiceLocator serviceLocator, Shell parentShell) {
+ super(ICommandIdProvider.OPEN_NEW_WIZARD, provider,
+ Messages.NewServerAction_text, serviceLocator, parentShell);
+ }
+}
@@ -35,6 +35,7 @@
import fr.opensagres.nosql.ide.ui.internal.actions.database.NewCollectionAction;
import fr.opensagres.nosql.ide.ui.internal.actions.database.NewDatabaseAction;
import fr.opensagres.nosql.ide.ui.internal.actions.database.NewDocumentAction;
+import fr.opensagres.nosql.ide.ui.internal.actions.servers.NewServerAction;
import fr.opensagres.nosql.ide.ui.internal.actions.servers.RunServerAction;
import fr.opensagres.nosql.ide.ui.internal.actions.servers.ServerRunnerAction;
import fr.opensagres.nosql.ide.ui.viewers.server.ServerLabelProvider;
@@ -46,6 +47,9 @@
private ServerTreeViewer viewer;
+ // Server type actions
+ Action newServerAction;
+
// Generic actions
private OpenAction openAction;
private DeleteAction deleteAction;
@@ -130,6 +134,7 @@ private void initializeActions(ISelectionProvider provider) {
// provider));
// }
+ createServerTypeActions(provider, actionBars);
createServerActions(provider, actionBars);
createGenericActions(provider, actionBars);
createDatabaseActions(provider, actionBars);
@@ -148,6 +153,12 @@ private void initializeActions(ISelectionProvider provider) {
IWorkbenchActionConstants.MB_ADDITIONS));
}
+ private void createServerTypeActions(ISelectionProvider provider,
+ IActionBars actionBars) {
+ newServerAction = new NewServerAction(provider, getSite(), getSite()
+ .getShell());
+ }
+
private void createServerActions(ISelectionProvider provider,
IActionBars actionBars) {
Map<IServerType, Collection<Action>> startRunnerActionsMap = new HashMap<IServerType, Collection<Action>>();
@@ -221,13 +232,17 @@ private void createDocumentActions(ISelectionProvider provider,
}
protected void fillContextMenu(Shell shell, IMenuManager menu) {
- menu.add(openAction);
- menu.add(refreshAction);
- menu.add(deleteAction);
- menu.add(new Separator());
Object selectedElement = getFirstSelectedElement(viewer);
if (selectedElement != null) {
- if (selectedElement instanceof ITreeSimpleNode) {
+ if (selectedElement instanceof IServerType) {
+ menu.add(newServerAction);
+ } else if (selectedElement instanceof ITreeSimpleNode) {
+
+ menu.add(openAction);
+ menu.add(refreshAction);
+ menu.add(deleteAction);
+ menu.add(new Separator());
+
switch (((ITreeSimpleNode) selectedElement).getType()) {
case NodeTypeConstants.Server:
menu.add(newDatabaseAction);

0 comments on commit 6488ea0

Please sign in to comment.