Author: DartPeng
Date: 2009-05-04 04:10:18 -0400 (Mon, 04 May 2009)
New Revision: 14998
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/actions/AddSmooksResourceAction.java
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksActionBarContributor.java
Log:
JBIDE-4260
Group the menu item for smooks-resource-list element
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/actions/AddSmooksResourceAction.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/actions/AddSmooksResourceAction.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/actions/AddSmooksResourceAction.java 2009-05-04
08:10:18 UTC (rev 14998)
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.smooks.configuration.actions;
+
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.ui.action.CreateChildAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * @author Dart (dpeng(a)redhat.com)
+ *
+ */
+public class AddSmooksResourceAction extends CreateChildAction {
+
+ public AddSmooksResourceAction(EditingDomain editingDomain, ISelection selection, Object
descriptor) {
+ super(editingDomain, selection, descriptor);
+ // TODO Auto-generated constructor stub
+ }
+
+ public AddSmooksResourceAction(IEditorPart editorPart, ISelection selection, Object
descriptor) {
+ super(editorPart, selection, descriptor);
+ // TODO Auto-generated constructor stub
+ }
+
+ public AddSmooksResourceAction(IWorkbenchPart workbenchPart, ISelection selection,
Object descriptor) {
+ super(workbenchPart, selection, descriptor);
+ // TODO Auto-generated constructor stub
+ }
+
+ public Object getDescriptor() {
+ return descriptor;
+ }
+
+ public void setDescriptor(Object descriptor) {
+ this.descriptor = descriptor;
+ }
+}
Property changes on:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/actions/AddSmooksResourceAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksActionBarContributor.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksActionBarContributor.java 2009-05-03
21:36:07 UTC (rev 14997)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksActionBarContributor.java 2009-05-04
08:10:18 UTC (rev 14998)
@@ -8,6 +8,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Iterator;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.ui.viewer.IViewerProvider;
@@ -19,7 +20,6 @@
import org.eclipse.emf.edit.domain.IEditingDomainProvider;
import org.eclipse.emf.edit.ui.action.ControlAction;
import org.eclipse.emf.edit.ui.action.CopyAction;
-import org.eclipse.emf.edit.ui.action.CreateChildAction;
import org.eclipse.emf.edit.ui.action.CreateSiblingAction;
import org.eclipse.emf.edit.ui.action.CutAction;
import org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor;
@@ -54,13 +54,26 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.jboss.tools.smooks.configuration.SmooksConfigurationActivator;
+import org.jboss.tools.smooks.configuration.actions.AddSmooksResourceAction;
+import org.jboss.tools.smooks.model.datasource.DataSourceJndi;
+import org.jboss.tools.smooks.model.datasource.Direct;
+import org.jboss.tools.smooks.model.dbrouting.Executor;
+import org.jboss.tools.smooks.model.dbrouting.ResultSetRowSelector;
+import org.jboss.tools.smooks.model.fileRouting.OutputStream;
+import org.jboss.tools.smooks.model.freemarker.Freemarker;
+import org.jboss.tools.smooks.model.groovy.ScriptType;
+import org.jboss.tools.smooks.model.iorouting.IORouter;
+import org.jboss.tools.smooks.model.javabean.BindingsType;
+import org.jboss.tools.smooks.model.jmsrouting.JmsRouter;
import org.jboss.tools.smooks.model.medi.EdiMap;
import org.jboss.tools.smooks.model.medi.MEdiFactory;
import org.jboss.tools.smooks.model.medi.MEdiPackage;
+import org.jboss.tools.smooks.model.smooks.AbstractReader;
import org.jboss.tools.smooks.model.smooks.DocumentRoot;
import org.jboss.tools.smooks.model.smooks.SmooksFactory;
import org.jboss.tools.smooks.model.smooks.SmooksPackage;
import org.jboss.tools.smooks.model.smooks.SmooksResourceListType;
+import org.jboss.tools.smooks.model.xsl.Xsl;
/**
* This is the action bar contributor for the Smooks model editor. <!--
@@ -278,7 +291,7 @@
// Prepare for CreateChild item addition or removal.
//
- createChildMenuManager = new MenuManager("New Child");
+ createChildMenuManager = new MenuManager("Add Smooks Resource");
submenuManager.insertBefore("additions", createChildMenuManager);
// Prepare for CreateSibling item addition or removal.
@@ -470,7 +483,7 @@
// }
if (descriptors != null) {
for (Object descriptor : descriptors) {
- actions.add(new CreateChildAction(activeEditorPart, selection, descriptor));
+ actions.add(new AddSmooksResourceAction(activeEditorPart, selection, descriptor));
}
}
return actions;
@@ -579,16 +592,167 @@
menuManager.insertBefore("edit", addMap10ResourceListAction);
}
- submenuManager = new MenuManager("Create Child");
- populateManager(submenuManager, createChildActions, null);
+ submenuManager = new MenuManager("Add Smooks Resource");
+ if (isSmooksResourceListElement()) {
+ groupActions(submenuManager,createChildActions);
+ } else {
+ populateManager(submenuManager, createChildActions, null);
+ }
menuManager.insertBefore("edit", submenuManager);
submenuManager = new MenuManager("Create Sibling");
populateManager(submenuManager, createSiblingActions, null);
menuManager.insertBefore("edit", submenuManager);
+ }
+ private boolean isSmooksResourceListElement() {
+ if (this.selection != null && selection instanceof IStructuredSelection) {
+ Object element = ((IStructuredSelection) selection).getFirstElement();
+ if (element instanceof SmooksResourceListType) {
+ return true;
+ }
+ }
+ return false;
}
+ protected void groupActions(MenuManager manager,Collection<?> createChildActions)
{
+ MenuManager readers = new MenuManager("Readers");
+ manager.add(readers);
+
+ MenuManager templating = new MenuManager("Templating");
+ manager.add(templating);
+
+ MenuManager jbinding = new MenuManager("Java Binding");
+ manager.add(jbinding);
+
+ MenuManager datasources = new MenuManager("Datasources");
+ manager.add(datasources);
+
+ MenuManager scripting = new MenuManager("Scripting");
+ manager.add(scripting);
+
+ MenuManager fragmentRouting = new MenuManager("Fragment Routing");
+ manager.add(fragmentRouting);
+
+ for (Iterator<?> iterator = createChildActions.iterator(); iterator.hasNext();)
{
+ boolean added = false;
+ AddSmooksResourceAction action = (AddSmooksResourceAction) iterator.next();
+ Object descriptor = action.getDescriptor();
+ if (isReader(descriptor)) {
+ readers.add(action);
+ added = true;
+ }
+ if (isTemplate(descriptor)) {
+ templating.add(action);added = true;
+ }
+ if (isJavaBinding(descriptor)) {
+ jbinding.add(action);added = true;
+ }
+ if (isDatasources(descriptor)) {
+ datasources.add(action);added = true;
+ }
+ if (isScripting(descriptor)) {
+ scripting.add(action);added = true;
+ }
+ if (isFragmentRouting(descriptor)) {
+ fragmentRouting.add(action);added = true;
+ }
+ if(!added){
+ manager.add(action);
+ }
+ }
+ }
+
+ private boolean isFragmentRouting(Object descriptor) {
+ if(descriptor instanceof CommandParameter){
+ CommandParameter parameter = (CommandParameter)descriptor;
+ if(parameter.getValue() != null){
+ if(AdapterFactoryEditingDomain.unwrap(parameter.getValue()) instanceof JmsRouter){
+ return true;
+ }
+ if(AdapterFactoryEditingDomain.unwrap(parameter.getValue()) instanceof
OutputStream){
+ return true;
+ }
+ if(AdapterFactoryEditingDomain.unwrap(parameter.getValue()) instanceof IORouter){
+ return true;
+ }
+ if(AdapterFactoryEditingDomain.unwrap(parameter.getValue()) instanceof Executor){
+ return true;
+ }
+ if(AdapterFactoryEditingDomain.unwrap(parameter.getValue()) instanceof
ResultSetRowSelector){
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean isScripting(Object descriptor) {
+ if(descriptor instanceof CommandParameter){
+ CommandParameter parameter = (CommandParameter)descriptor;
+ if(parameter.getValue() != null){
+ if(AdapterFactoryEditingDomain.unwrap(parameter.getValue()) instanceof ScriptType){
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean isDatasources(Object descriptor) {
+ if(descriptor instanceof CommandParameter){
+ CommandParameter parameter = (CommandParameter)descriptor;
+ if(parameter.getValue() != null){
+ if(AdapterFactoryEditingDomain.unwrap(parameter.getValue()) instanceof
DataSourceJndi){
+ return true;
+ }
+ if(AdapterFactoryEditingDomain.unwrap(parameter.getValue()) instanceof Direct){
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean isJavaBinding(Object descriptor) {
+ if(descriptor instanceof CommandParameter){
+ CommandParameter parameter = (CommandParameter)descriptor;
+ if(parameter.getValue() != null){
+ if(AdapterFactoryEditingDomain.unwrap(parameter.getValue()) instanceof
BindingsType){
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean isTemplate(Object descriptor) {
+ if(descriptor instanceof CommandParameter){
+ CommandParameter parameter = (CommandParameter)descriptor;
+ if(parameter.getValue() != null){
+ if(AdapterFactoryEditingDomain.unwrap(parameter.getValue()) instanceof Freemarker){
+ return true;
+ }
+ if(AdapterFactoryEditingDomain.unwrap(parameter.getValue()) instanceof Xsl){
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean isReader(Object descriptor) {
+ if(descriptor instanceof CommandParameter){
+ CommandParameter parameter = (CommandParameter)descriptor;
+ if(parameter.getValue() != null){
+ if(AdapterFactoryEditingDomain.unwrap(parameter.getValue()) instanceof
AbstractReader){
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
protected void updateRootElementAddAction() {
addSmooks11ResourceListAction.setEnabled(false);
addMap10ResourceListAction.setEnabled(false);