Author: DartPeng
Date: 2008-12-22 03:58:38 -0500 (Mon, 22 Dec 2008)
New Revision: 12801
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/commandprocessor/JavaBeanModelCommandProcessor.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/commandprocessor/CommandProcessorFactory.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/commandprocessor/ICommandProcessor.java
Log:
Connect the parent link automatically
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/commandprocessor/JavaBeanModelCommandProcessor.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/commandprocessor/JavaBeanModelCommandProcessor.java 2008-12-22
07:19:22 UTC (rev 12800)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/commandprocessor/JavaBeanModelCommandProcessor.java 2008-12-22
08:58:38 UTC (rev 12801)
@@ -10,12 +10,18 @@
******************************************************************************/
package org.jboss.tools.smooks.javabean.commandprocessor;
+import java.util.List;
+
import org.eclipse.emf.common.command.Command;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.jface.viewers.ITreeContentProvider;
import org.jboss.tools.smooks.javabean.model.JavaBeanModel;
import org.jboss.tools.smooks.ui.gef.commandprocessor.ICommandProcessor;
import org.jboss.tools.smooks.ui.gef.commands.CreateConnectionCommand;
import org.jboss.tools.smooks.ui.gef.model.AbstractStructuredDataModel;
+import org.jboss.tools.smooks.ui.gef.model.IConnectableModel;
import org.jboss.tools.smooks.ui.gef.model.PropertyModel;
+import org.jboss.tools.smooks.ui.modelparser.SmooksConfigurationFileGenerateContext;
import org.jboss.tools.smooks.utils.UIUtils;
/**
@@ -25,21 +31,29 @@
*/
public class JavaBeanModelCommandProcessor implements ICommandProcessor {
- public void processEMFCommand(Command emfCommand) {
+ public void processEMFCommand(Command emfCommand,
+ SmooksConfigurationFileGenerateContext context) {
}
- public void processGEFCommand(org.eclipse.gef.commands.Command gefCommand) {
+ public void processGEFCommand(org.eclipse.gef.commands.Command gefCommand,
+ SmooksConfigurationFileGenerateContext context) {
+ Object source = null;
+ JavaBeanModel target = null;
if (CreateConnectionCommand.class.isAssignableFrom(gefCommand
.getClass())) {
CreateConnectionCommand command = (CreateConnectionCommand) gefCommand;
if (command.getSource() != null && command.getTarget() != null) {
Object m = command.getTarget();
Object s = command.getSource();
- if (m instanceof AbstractStructuredDataModel && s instanceof
AbstractStructuredDataModel) {
- Object source = ((AbstractStructuredDataModel)s).getReferenceEntityModel();
- Object t = ((AbstractStructuredDataModel)m).getReferenceEntityModel();
- if (!UIUtils.isInstanceCreatingConnection(source,t)) {
+ if (m instanceof AbstractStructuredDataModel
+ && s instanceof AbstractStructuredDataModel) {
+ source = ((AbstractStructuredDataModel) s)
+ .getReferenceEntityModel();
+ Object t = ((AbstractStructuredDataModel) m)
+ .getReferenceEntityModel();
+ if (!UIUtils.isInstanceCreatingConnection(source, t)) {
if (t instanceof JavaBeanModel) {
+ target = (JavaBeanModel) t;
Class clazz = ((JavaBeanModel) t).getBeanClass();
if (clazz != null && clazz != String.class) {
PropertyModel property = new PropertyModel();
@@ -51,24 +65,84 @@
}
}
}
+
+ CompoundCommand compoundCommand = new CompoundCommand();
+ fillCreateParentLinkCommand(compoundCommand, source, target,
+ context);
+ if (!compoundCommand.isEmpty()) {
+ compoundCommand.execute();
+ }
}
}
+ private void fillCreateParentLinkCommand(CompoundCommand compoundCommand,
+ Object source, JavaBeanModel target,
+ SmooksConfigurationFileGenerateContext context) {
+ CreateConnectionCommand c = createParentLinkCommand(source, target,
+ context);
+ while (c != null) {
+ compoundCommand.add(c);
+ Object m = c.getTarget();
+ Object s = c.getSource();
+ Object source1 = null;
+ JavaBeanModel target1 = null;
+ if (m instanceof AbstractStructuredDataModel
+ && s instanceof AbstractStructuredDataModel) {
+ source1 = ((AbstractStructuredDataModel) s)
+ .getReferenceEntityModel();
+ target1 = (JavaBeanModel) ((AbstractStructuredDataModel) m)
+ .getReferenceEntityModel();
+ }
+ c = createParentLinkCommand(source1, target1, context);
+ }
+ }
+
+ private CreateConnectionCommand createParentLinkCommand(Object source,
+ JavaBeanModel target, SmooksConfigurationFileGenerateContext context) {
+ ITreeContentProvider sourceProvider = context.getSourceViewerProvider();
+ JavaBeanModel targetParent = target.getParent();
+ AbstractStructuredDataModel targetParentGraphModel = UIUtils
+ .findGraphModel(context.getGraphicalRootModel(), targetParent);
+ if (targetParentGraphModel != null
+ && targetParentGraphModel instanceof IConnectableModel) {
+ List list = ((IConnectableModel) targetParentGraphModel)
+ .getModelTargetConnections();
+ if (list.isEmpty()) {
+ Object sourceParent = sourceProvider.getParent(source);
+ IConnectableModel sourceParentGraphModel = (IConnectableModel) UIUtils
+ .findGraphModel(context.getGraphicalRootModel(),
+ sourceParent);
+ if (sourceParentGraphModel != null) {
+ CreateConnectionCommand connectionCommand = new CreateConnectionCommand();
+ connectionCommand.setSource(sourceParentGraphModel);
+ connectionCommand.setTarget(targetParentGraphModel);
+ return connectionCommand;
+ }
+ }
+ }
+ return null;
+ }
+
public static String getTypeString(Class clazz) {
- if(clazz.isPrimitive()){
+ if (clazz.isPrimitive()) {
return getPrimitiveTypeString(clazz);
}
String name = clazz.getSimpleName();
return name;
}
-
- public static String getPrimitiveTypeString(Class clazz){
+
+ public static String getPrimitiveTypeString(Class clazz) {
String name = clazz.getName();
- if("int".equalsIgnoreCase(name)) return "Integer";
- if("double".equalsIgnoreCase(name)) return "Double";
- if("float".equalsIgnoreCase(name)) return "Float";
- if("long".equalsIgnoreCase(name)) return "Long";
- if("boolean".equalsIgnoreCase(name)) return "Boolean";
+ if ("int".equalsIgnoreCase(name))
+ return "Integer";
+ if ("double".equalsIgnoreCase(name))
+ return "Double";
+ if ("float".equalsIgnoreCase(name))
+ return "Float";
+ if ("long".equalsIgnoreCase(name))
+ return "Long";
+ if ("boolean".equalsIgnoreCase(name))
+ return "Boolean";
return "";
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java 2008-12-22
07:19:22 UTC (rev 12800)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java 2008-12-22
08:58:38 UTC (rev 12801)
@@ -478,10 +478,8 @@
protected void createErrorMessageLinkGUI(FormToolkit toolkit,
Composite parent) {
- problemSection = this
- .createPageSectionHeader(parent, Section.TITLE_BAR
- | Section.EXPANDED, "Problems",
- "No problems");
+ problemSection = this.createPageSectionHeader(parent, Section.TITLE_BAR
+ | Section.EXPANDED, "Problems", "No problems");
designTimeAnalyzeResultRegion = toolkit.createComposite(problemSection);
GridLayout ngl = new GridLayout();
ngl.numColumns = 2;
@@ -821,18 +819,20 @@
context.setDataMappingRootModel(this.rootModel);
context.setSmooksConfigFile(((IFileEditorInput) getEditorInput())
.getFile());
-
- context.setSourceViewerLabelProvider((LabelProvider) sourceViewer
- .getLabelProvider());
- context
- .setSourceViewerContentProvider((ITreeContentProvider) sourceViewer
- .getContentProvider());
-
+ if (sourceViewer != null) {
+ context.setSourceViewerLabelProvider((LabelProvider) sourceViewer
+ .getLabelProvider());
+ context
+ .setSourceViewerContentProvider((ITreeContentProvider) sourceViewer
+ .getContentProvider());
+ }
+ if (targetViewer != null) {
context.setTargetViewerLabelProvider((LabelProvider) targetViewer
.getLabelProvider());
context
.setTargetViewerContentProvider((ITreeContentProvider) targetViewer
.getContentProvider());
+ }
context.setShell(getSite().getShell());
}
@@ -1465,6 +1465,7 @@
public SmooksConfigurationFileGenerateContext
getSmooksConfigurationFileGenerateContext() {
if (smooksConfigurationFileGenerateContext == null) {
smooksConfigurationFileGenerateContext = createContext();
+ initSmooksConfigurationFileGenerateContext(smooksConfigurationFileGenerateContext);
}
return smooksConfigurationFileGenerateContext;
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/commandprocessor/CommandProcessorFactory.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/commandprocessor/CommandProcessorFactory.java 2008-12-22
07:19:22 UTC (rev 12800)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/commandprocessor/CommandProcessorFactory.java 2008-12-22
08:58:38 UTC (rev 12801)
@@ -18,6 +18,7 @@
import org.eclipse.ui.IEditorPart;
import org.jboss.tools.smooks.ui.editors.SmooksFormEditor;
import org.jboss.tools.smooks.ui.editors.SmooksGraphicalFormPage;
+import org.jboss.tools.smooks.ui.modelparser.SmooksConfigurationFileGenerateContext;
import org.jboss.tools.smooks.utils.SmooksExtensionPointConstants;
/**
@@ -76,18 +77,17 @@
if(page != null){
String sourceId = page.getSourceDataTypeID();
String targetId = page.getTargetDataTypeID();
- processGEFCommand(command, sourceId,targetId);
+ processGEFCommand(command,
sourceId,targetId,page.getSmooksConfigurationFileGenerateContext());
}
}
}
-
}
public void processGEFCommand(Command command, String sourceId,
- String targetId) throws CoreException {
+ String targetId , SmooksConfigurationFileGenerateContext context) throws
CoreException {
ICommandProcessor pro = getCommandProcessor(sourceId, targetId);
if (pro != null) {
- pro.processGEFCommand(command);
+ pro.processGEFCommand(command , context);
}
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/commandprocessor/ICommandProcessor.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/commandprocessor/ICommandProcessor.java 2008-12-22
07:19:22 UTC (rev 12800)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/gef/commandprocessor/ICommandProcessor.java 2008-12-22
08:58:38 UTC (rev 12801)
@@ -1,6 +1,7 @@
package org.jboss.tools.smooks.ui.gef.commandprocessor;
import org.eclipse.gef.commands.Command;
+import org.jboss.tools.smooks.ui.modelparser.SmooksConfigurationFileGenerateContext;
/**
*
@@ -9,8 +10,7 @@
* @CreateTime Jul 22, 2008
*/
public interface ICommandProcessor {
- public void processGEFCommand(Command gefCommand);
+ public void processGEFCommand(Command gefCommand ,
SmooksConfigurationFileGenerateContext context);
- public void processEMFCommand(
- org.eclipse.emf.common.command.Command emfCommand);
+ public void processEMFCommand(org.eclipse.emf.common.command.Command emfCommand,
SmooksConfigurationFileGenerateContext context);
}