Author: DartPeng
Date: 2008-10-26 07:43:48 -0400 (Sun, 26 Oct 2008)
New Revision: 11186
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/analyzer/CompositeResolveCommand.java
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/analyzer/Java2JavaResolveCommand.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/analyzer/JavaBeanAnalyzer.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java
Log:
JBIDE-2867
add menu for error label
if user right-click the error label , menu will show how to resolve this error , and user
select the menu-item , the editor will execute the resolve command
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/analyzer/CompositeResolveCommand.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/analyzer/CompositeResolveCommand.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/analyzer/CompositeResolveCommand.java 2008-10-26
11:43:48 UTC (rev 11186)
@@ -0,0 +1,49 @@
+/**
+ *
+ */
+package org.jboss.tools.smooks.analyzer;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.tools.smooks.ui.modelparser.SmooksConfigurationFileGenerateContext;
+
+/**
+ * @author Dart
+ *
+ */
+public class CompositeResolveCommand extends ResolveCommand {
+
+ private List<ResolveCommand> commandList = new ArrayList<ResolveCommand>();
+
+ public CompositeResolveCommand(
+ SmooksConfigurationFileGenerateContext context) {
+ super(context);
+ }
+
+
+ public void addCommand(ResolveCommand command){
+ commandList.add(command);
+ }
+
+ public void removeCommand(ResolveCommand command){
+ commandList.remove(command);
+ }
+
+ public boolean isEmpty(){
+ if(commandList == null) return true;
+ return commandList.isEmpty();
+ }
+
+ @Override
+ public void execute() throws Exception {
+ if(commandList == null) return;
+ for (Iterator<ResolveCommand> iterator = commandList.iterator();
iterator.hasNext();) {
+ ResolveCommand command = (ResolveCommand) iterator.next();
+ command.execute();
+ }
+ }
+
+
+}
Property changes on:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/analyzer/CompositeResolveCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/analyzer/Java2JavaResolveCommand.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/analyzer/Java2JavaResolveCommand.java 2008-10-26
11:33:25 UTC (rev 11185)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/analyzer/Java2JavaResolveCommand.java 2008-10-26
11:43:48 UTC (rev 11186)
@@ -3,8 +3,14 @@
*/
package org.jboss.tools.smooks.javabean.analyzer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import org.jboss.tools.smooks.analyzer.ResolveCommand;
-import org.jboss.tools.smooks.javabean.model.JavaBeanModel;
+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.LineConnectionModel;
import org.jboss.tools.smooks.ui.modelparser.SmooksConfigurationFileGenerateContext;
/**
@@ -13,25 +19,29 @@
*/
public class Java2JavaResolveCommand extends ResolveCommand {
- private JavaBeanModel sourceModel;
+ private AbstractStructuredDataModel sourceModel;
- private JavaBeanModel targetModel;
+ private AbstractStructuredDataModel targetModel;
+ private List<LineConnectionModel> disconnectionModel = new
ArrayList<LineConnectionModel>();
-
- public JavaBeanModel getSourceModel() {
+ public void addDisconnectionModel(LineConnectionModel line){
+ disconnectionModel.add(line);
+ }
+
+ public AbstractStructuredDataModel getSourceModel() {
return sourceModel;
}
- public void setSourceModel(JavaBeanModel sourceModel) {
+ public void setSourceModel(AbstractStructuredDataModel sourceModel) {
this.sourceModel = sourceModel;
}
- public JavaBeanModel getTargetModel() {
+ public AbstractStructuredDataModel getTargetModel() {
return targetModel;
}
- public void setTargetModel(JavaBeanModel targetModel) {
+ public void setTargetModel(AbstractStructuredDataModel targetModel) {
this.targetModel = targetModel;
}
@@ -42,9 +52,23 @@
@Override
public void execute() throws Exception {
-
SmooksConfigurationFileGenerateContext context = getContext();
if(context == null) throw new RuntimeException("Smooks generated context is
NULL");
-
+ if(sourceModel != null && targetModel != null){
+ LineConnectionModel connectionModel = new LineConnectionModel();
+ connectionModel
+ .setSource((IConnectableModel) sourceModel);
+ connectionModel
+ .setTarget((IConnectableModel) targetModel);
+ connectionModel.connect();
+ return;
+ }
+ if(!disconnectionModel.isEmpty()){
+ for (Iterator<LineConnectionModel> iterator = disconnectionModel.iterator();
iterator.hasNext();) {
+ LineConnectionModel connection = (LineConnectionModel) iterator.next();
+ connection.disConnect();
+ }
+ return;
+ }
}
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/analyzer/JavaBeanAnalyzer.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/analyzer/JavaBeanAnalyzer.java 2008-10-26
11:33:25 UTC (rev 11185)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/javabean/analyzer/JavaBeanAnalyzer.java 2008-10-26
11:43:48 UTC (rev 11186)
@@ -33,13 +33,13 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
+import org.jboss.tools.smooks.analyzer.CompositeResolveCommand;
import org.jboss.tools.smooks.analyzer.DesignTimeAnalyzeResult;
import org.jboss.tools.smooks.analyzer.IMappingAnalyzer;
import org.jboss.tools.smooks.analyzer.ISourceModelAnalyzer;
import org.jboss.tools.smooks.analyzer.ITargetModelAnalyzer;
import org.jboss.tools.smooks.analyzer.MappingModel;
import org.jboss.tools.smooks.analyzer.MappingResourceConfigList;
-import org.jboss.tools.smooks.analyzer.ResolveCommand;
import org.jboss.tools.smooks.analyzer.SmooksAnalyzerException;
import org.jboss.tools.smooks.graphical.GraphInformations;
import org.jboss.tools.smooks.graphical.Param;
@@ -392,14 +392,13 @@
if (((IConnectableModel) pgm)
.getModelTargetConnections().isEmpty()) {
String errorMessage = "The parent of Java node \""
- + javaModel.getName()
- + "\" : \""
- + parent.getName()
- + "\" doesn't be connected by any source node";
+ + javaModel.getName()
+ + "\" : \""
+ + parent.getName()
+ + "\" doesn't be connected by any source node";
DesignTimeAnalyzeResult dr = new DesignTimeAnalyzeResult();
dr.setErrorMessage(errorMessage);
- Java2JavaResolveCommand command = new Java2JavaResolveCommand(context);
-// command.setResolveDescription(resolveDescription);
+ createResolveCommand(dr, context, javaModel, parent);
arList.add(dr);
}
}
@@ -409,6 +408,63 @@
return arList.toArray(new DesignTimeAnalyzeResult[0]);
}
+ private void createResolveCommand(DesignTimeAnalyzeResult result,
+ SmooksConfigurationFileGenerateContext context,
+ JavaBeanModel currentNode, JavaBeanModel parentNode) {
+ GraphRootModel root = context.getGraphicalRootModel();
+ HashMap<AbstractStructuredDataModel, AbstractStructuredDataModel> tempMap = new
HashMap<AbstractStructuredDataModel, AbstractStructuredDataModel>();
+ // Disconnect all connections command
+ Java2JavaResolveCommand disconnectCommand = new Java2JavaResolveCommand(
+ context);
+ CompositeResolveCommand compositeCommand = new CompositeResolveCommand(
+ context);
+ compositeCommand.setResolveDescription("Connect all needed connections");
+ disconnectCommand
+ .setResolveDescription("Disconnect all connections of the current \""
+ + currentNode.getName() + "\"node");
+ AbstractStructuredDataModel targetNode = UIUtils.findGraphModel(root,
+ currentNode);
+ if (targetNode instanceof IConnectableModel) {
+ List<Object> connections = ((IConnectableModel) targetNode)
+ .getModelTargetConnections();
+ for (Iterator iterator = connections.iterator(); iterator.hasNext();) {
+ LineConnectionModel line = (LineConnectionModel) iterator
+ .next();
+ AbstractStructuredDataModel source = (AbstractStructuredDataModel) line
+ .getSource();
+ JavaBeanModel sourceBean = (JavaBeanModel) source
+ .getReferenceEntityModel();
+ JavaBeanModel sourceParent = sourceBean.getParent();
+ if (sourceParent == null) {
+ sourceParent = sourceBean;
+ }
+ AbstractStructuredDataModel sourceParentNode = UIUtils
+ .findGraphModel(root, sourceParent);
+ // Connect the parent command
+ AbstractStructuredDataModel targetParentNode = UIUtils
+ .findGraphModel(root, parentNode);
+ if (tempMap.get(sourceParentNode) == null) {
+ Java2JavaResolveCommand connectParent = new Java2JavaResolveCommand(
+ context);
+ connectParent.setResolveDescription("Connect the \""
+ + sourceParent.getName() + "\" to the \""
+ + parentNode.getName() + "\"");
+ connectParent.setSourceModel(sourceParentNode);
+ connectParent.setTargetModel(targetParentNode);
+ result.addResolveCommand(connectParent);
+ tempMap.put(sourceParentNode,targetParentNode);
+ compositeCommand.addCommand(connectParent);
+ }
+
+ disconnectCommand.addDisconnectionModel(line);
+ }
+ }
+ result.addResolveCommand(disconnectCommand);
+ if (!compositeCommand.isEmpty()) {
+ result.addResolveCommand(compositeCommand);
+ }
+ }
+
/**
* If root node don't connect , it will ask user to connect them .
*
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-10-26
11:33:25 UTC (rev 11185)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/editors/SmooksGraphicalFormPage.java 2008-10-26
11:43:48 UTC (rev 11186)
@@ -123,6 +123,7 @@
import org.jboss.tools.smooks.model.SmooksFactory;
import org.jboss.tools.smooks.model.SmooksResourceListType;
import org.jboss.tools.smooks.model.util.SmooksModelConstants;
+import org.jboss.tools.smooks.model.util.SmooksModelUtils;
import org.jboss.tools.smooks.ui.IStructuredDataCreationWizard;
import org.jboss.tools.smooks.ui.IViewerInitor;
import org.jboss.tools.smooks.ui.SmooksUIActivator;
@@ -1285,13 +1286,13 @@
SmooksGraphConstants.IMAGE_ERROR));
Label notifyLabel = new Label(designTimeAnalyzeResultRegion,
SWT.NONE);
- Menu menu = new Menu(getSite().getShell(),SWT.POP_UP);
+ Menu menu = new Menu(getSite().getShell(), SWT.POP_UP);
List<ResolveCommand> list = result.getResolveProblem();
for (Iterator iterator2 = list.iterator(); iterator2.hasNext();) {
final ResolveCommand resolveCommand = (ResolveCommand) iterator2
.next();
- MenuItem item = new MenuItem(menu,SWT.NONE);
- item.addSelectionListener(new SelectionListener(){
+ MenuItem item = new MenuItem(menu, SWT.NONE);
+ item.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent arg0) {
widgetSelected(arg0);
@@ -1300,10 +1301,15 @@
public void widgetSelected(SelectionEvent arg0) {
try {
resolveCommand.execute();
+ commandStackChanged = true;
+ analyzeDesignGraph();
+ firePropertyChange(PROP_DIRTY);
} catch (Exception e) {
+ UIUtils.showErrorDialog(getSite().getShell(),
+ UIUtils.createErrorStatus(e));
}
}
-
+
});
item.setText(resolveCommand.getResolveDescription());
item.setImage(resolveCommand.getImage());
@@ -1336,8 +1342,7 @@
}
updateNotifyMessage();
} catch (CoreException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ UIUtils.showErrorDialog(getSite().getShell(), UIUtils.createErrorStatus(e));
}
}