Author: DartPeng
Date: 2010-01-05 02:33:17 -0500 (Tue, 05 Jan 2010)
New Revision: 19643
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksResourceChangeListener.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/AbstractSmooksFormEditor.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/freemarker/FreemarkerTemplateNodeGraphicalModel.java
Log:
JBIDE-5561
Fixed it.
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksResourceChangeListener.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksResourceChangeListener.java 2010-01-04
21:27:33 UTC (rev 19642)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksResourceChangeListener.java 2010-01-05
07:33:17 UTC (rev 19643)
@@ -11,26 +11,25 @@
package org.jboss.tools.smooks.configuration.editors;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.resources.IResourceStatus;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.content.IContentDescription;
+import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.jboss.tools.smooks.configuration.SmooksConstants;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.jboss.tools.smooks.configuration.SmooksConfigurationActivator;
+import org.jboss.tools.smooks.editor.AbstractSmooksFormEditor;
/**
* @author Dart (dpeng(a)redhat.com)
@@ -38,6 +37,7 @@
* Apr 12, 2009
*/
public class SmooksResourceChangeListener implements IResourceChangeListener {
+ public static final String SMOOKS_CONTENTTYPE_ID =
"org.jboss.tools.smooks.ui.smooks.contentType";
/*
* (non-Javadoc)
@@ -50,7 +50,7 @@
try {
switch (event.getType()) {
case IResourceChangeEvent.POST_CHANGE:
- event.getDelta().accept(new DeltaPrinter());
+ event.getDelta().accept(new ChangePartNameVisitor());
break;
}
} catch (Exception e) {
@@ -59,110 +59,104 @@
}
- private void deleteFile(IPath path) {
- final IPath path1 = path;
- WorkspaceJob job = new WorkspaceJob("Delete file") { //$NON-NLS-1$
- public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
- IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path1);
- if (file.exists()) {
- file.delete(true, monitor);
- }
- return Status.OK_STATUS;
- }
- };
- job.schedule();
- }
+ class ChangePartNameVisitor implements IResourceDeltaVisitor {
- private void newFile(IPath path, IPath newPath) {
- final IPath path1 = path;
- final IPath newPath1 = newPath;
- WorkspaceJob job = new WorkspaceJob("New file and delete old file") {
//$NON-NLS-1$
- public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
- IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path1);
- if (file.exists()) {
- IFile newFile = ResourcesPlugin.getWorkspace().getRoot().getFile(newPath1);
- if (newFile.exists()) {
- if (MessageDialog.openQuestion(new Shell(Display.getDefault()),
- "Cover File?", "Do you want to cover " //$NON-NLS-1$
//$NON-NLS-2$
- + newFile.getFullPath())) { //$NON-NLS-1$
- newFile.setContents(file.getContents(), true, true, monitor);
- }
- } else {
- newFile.create(file.getContents(), true, monitor);
- }
- file.delete(true, monitor);
- }
- return Status.OK_STATUS;
- }
+// int count = 0;
- };
- job.schedule();
- }
-
- class DeltaPrinter implements IResourceDeltaVisitor {
-
- int count = 0;
-
public boolean visit(IResourceDelta delta) {
IResource res = delta.getResource();
- String fileExtension = res.getFileExtension();
- if (!SmooksConstants.SMOOKS_EXTENTION_NAME.equals(fileExtension)) { //$NON-NLS-1$
- return true;
- }
- int flags = delta.getFlags();
- switch (delta.getKind()) {
- case IResourceDelta.ADDED:
- if (flags == IResourceDelta.MOVED_FROM) {
- IPath path = delta.getMovedFromPath();
- String fileName = ""; //$NON-NLS-1$
- if (path != null) {
- fileName = path.lastSegment();
- int dotIndex = fileName.lastIndexOf("."); //$NON-NLS-1$
- if (dotIndex != -1) {
- fileExtension = fileName.substring(dotIndex + 1, fileName.length());
- }
- if (!SmooksConstants.SMOOKS_EXTENTION_NAME.equals(fileExtension)) { //$NON-NLS-1$
- return true;
- }
- fileName += SmooksConstants.SMOOKS_GRAPHICSEXT_EXTENTION_NAME_WITHDOT;
//$NON-NLS-1$
- path = path.removeLastSegments(1);
- path = path.append(fileName);
+ if (res instanceof IFile) {
+ IFile file = (IFile) res;
+ IContentDescription contentDescription;
+ IContentType contentType = null;
+ try {
+ contentDescription = file.getContentDescription();
+ if (contentDescription == null) {
+ return true;
}
+ contentType = contentDescription.getContentType();
- IPath newPath = res.getFullPath();
- fileName = newPath.lastSegment();
- fileName += SmooksConstants.SMOOKS_GRAPHICSEXT_EXTENTION_NAME_WITHDOT;
//$NON-NLS-1$
- newPath = newPath.removeLastSegments(1).append(fileName);
- newFile(path, newPath);
+ } catch (CoreException e) {
+ if (e.getStatus().getCode() == IResourceStatus.OUT_OF_SYNC_LOCAL) {
+ // Determine the content type from the file name.
+ contentType = Platform.getContentTypeManager().findContentTypeFor(file.getName());
+ }
}
- break;
- case IResourceDelta.REMOVED:
- if (flags == IResourceDelta.MOVED_TO) {
- break;
+ if (contentType == null || !SMOOKS_CONTENTTYPE_ID.equals(contentType.getId())) {
+ return true;
}
- IProject project = res.getProject();
- try {
- if (project.isOpen()) {
- IProjectNature nature = project.getNature(JavaCore.NATURE_ID);
- if (nature != null) {
- IJavaProject javaProject = JavaCore.create(project);
- IPath outPut = javaProject.getOutputLocation();
- IPath removeRes = res.getFullPath();
- if (outPut.isPrefixOf(removeRes)) {
- break;
- }
+ int flags = delta.getFlags();
+ switch (delta.getKind()) {
+ case IResourceDelta.ADDED:
+ if (flags == IResourceDelta.MOVED_FROM) {
+ IPath path = delta.getMovedFromPath();
+ String fileName = ""; //$NON-NLS-1$
+ if (path != null) {
+ fileName = path.lastSegment();
}
+
+ IPath newPath = res.getFullPath();
+ String newfileName = newPath.lastSegment();
+ if (newfileName.equals(fileName)) {
+ return true;
+ }
+ final String newPartName = newfileName;
+ final IPath fOldPath = path;
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ IWorkbenchWindow window =
SmooksConfigurationActivator.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow();
+ if (window != null) {
+ IEditorReference[] editorReferences =
window.getActivePage().getEditorReferences();
+ for (int i = 0; i < editorReferences.length; i++) {
+ IEditorReference iEditorReference = editorReferences[i];
+ IEditorPart editorPart = iEditorReference.getEditor(false);
+ IEditorInput editorInput = editorPart.getEditorInput();
+ if (editorInput instanceof IFileEditorInput) {
+ IFile relatedFile = ((IFileEditorInput) editorInput).getFile();
+ if (relatedFile != null && relatedFile.getFullPath().equals(fOldPath))
{
+ if (editorPart instanceof AbstractSmooksFormEditor) {
+ ((AbstractSmooksFormEditor) editorPart).setPartName(newPartName);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ });
}
- } catch (CoreException e) {
- e.printStackTrace();
+ break;
+ case IResourceDelta.REMOVED:
+ // if (flags == IResourceDelta.MOVED_TO) {
+ // break;
+ // }
+ // IProject project = res.getProject();
+ // try {
+ // if (project.isOpen()) {
+ // IProjectNature nature =
+ // project.getNature(JavaCore.NATURE_ID);
+ // if (nature != null) {
+ // IJavaProject javaProject = JavaCore.create(project);
+ // IPath outPut = javaProject.getOutputLocation();
+ // IPath removeRes = res.getFullPath();
+ // if (outPut.isPrefixOf(removeRes)) {
+ // break;
+ // }
+ // }
+ // }
+ // } catch (CoreException e) {
+ // e.printStackTrace();
+ // }
+ // IPath path = res.getFullPath();
+ // String fileName = path.lastSegment();
+ // fileName += SmooksConstants.SMOOKS_GRAPHICSEXT_EXTENTION_NAME_WITHDOT;
//$NON-NLS-1$
+ // path = path.removeLastSegments(1).append(fileName);
+ // deleteFile(path);
+ break;
}
- IPath path = res.getFullPath();
- String fileName = path.lastSegment();
- fileName += SmooksConstants.SMOOKS_GRAPHICSEXT_EXTENTION_NAME_WITHDOT; //$NON-NLS-1$
- path = path.removeLastSegments(1).append(fileName);
- deleteFile(path);
- break;
}
return true; // visit the children
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/AbstractSmooksFormEditor.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/AbstractSmooksFormEditor.java 2010-01-04
21:27:33 UTC (rev 19642)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/AbstractSmooksFormEditor.java 2010-01-05
07:33:17 UTC (rev 19643)
@@ -652,6 +652,10 @@
monitor.done();
}
}
+
+ public void setPartName(String partName){
+ super.setPartName(partName);
+ }
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java 2010-01-04
21:27:33 UTC (rev 19642)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java 2010-01-05
07:33:17 UTC (rev 19643)
@@ -434,7 +434,9 @@
for (Iterator<?> iterator = temp.iterator(); iterator.hasNext();) {
TreeNodeConnection treeNodeConnection = (TreeNodeConnection) iterator.next();
AbstractSmooksGraphicalModel target = treeNodeConnection.getTargetNode();
- String refID = command.getValue().toString();
+ Object refValue = command.getValue();
+ if(refValue == null) continue;
+ String refID = refValue.toString();
Object targetModel = AdapterFactoryEditingDomain.unwrap(target.getData());
if (targetModel instanceof EObject) {
EStructuralFeature idfeature = SmooksUIUtils.getBeanIDFeature((EObject)
targetModel);
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/freemarker/FreemarkerTemplateNodeGraphicalModel.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/freemarker/FreemarkerTemplateNodeGraphicalModel.java 2010-01-04
21:27:33 UTC (rev 19642)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/model/freemarker/FreemarkerTemplateNodeGraphicalModel.java 2010-01-05
07:33:17 UTC (rev 19643)
@@ -149,8 +149,9 @@
connection.setData(mapping);
}
if (isMappingValueConnection(connection)) {
+ JavaBeanGraphModel collectionJavaBean =
getCollectionRootBeanModel(connection.getSourceNode());
String mappingString =
FreemarkerCSVContentGenerator.generateMappingString(connection.getSourceNode(),
- getCollectionRootBeanModel());
+ collectionJavaBean);
Mapping mapping = builder.addValueMapping(mappingString, node);
connection.setData(mapping);
}
@@ -160,7 +161,49 @@
}
}
- protected JavaBeanGraphModel getCollectionRootBeanModel() {
+ protected JavaBeanGraphModel getCollectionRootBeanModel(AbstractSmooksGraphicalModel
sourceNode) {
+ AbstractSmooksGraphicalModel parentNodeBean = sourceNode;
+ while (parentNodeBean != null && !(parentNodeBean instanceof
JavaBeanGraphModel)) {
+ parentNodeBean = parentNodeBean.getParent();
+ }
+ if (parentNodeBean != null && parentNodeBean instanceof JavaBeanGraphModel) {
+ // get the bean reference links
+ List<TreeNodeConnection> connections = parentNodeBean.getTargetConnections();
+ for (Iterator<?> iterator = connections.iterator(); iterator.hasNext();) {
+ TreeNodeConnection treeNodeConnection = (TreeNodeConnection) iterator.next();
+ // check if the node is "collection bean" node , if is not ,
+ // check its parent node.
+ AbstractSmooksGraphicalModel collectionJavaBean =
treeNodeConnection.getSourceNode();
+ collectionJavaBean = collectionJavaBean.getParent();
+ if (collectionJavaBean instanceof JavaBeanGraphModel) {
+ Object data = collectionJavaBean.getData();
+ data = AdapterFactoryEditingDomain.unwrap(data);
+ if (data != null && data instanceof EObject) {
+ if (SmooksUIUtils.isCollectionJavaGraphModel((EObject) data)) {
+ return (JavaBeanGraphModel) collectionJavaBean;
+ // check if it was linked with the "many" template node
+// List<TreeNodeConnection> collectionLinks =
collectionJavaBean.getSourceConnections();
+// for (Iterator<?> iterator2 = collectionLinks.iterator();
iterator2.hasNext();) {
+// TreeNodeConnection treeNodeConnection2 = (TreeNodeConnection)
iterator2.next();
+// AbstractSmooksGraphicalModel templateNode =
treeNodeConnection2.getTargetNode();
+// if(templateNode instanceof FreemarkerTemplateNodeGraphicalModel){
+// Object templateData =
((FreemarkerTemplateNodeGraphicalModel)templateNode).getData();
+// if(templateData instanceof IFreemarkerTemplateModel){
+// if(((IFreemarkerTemplateModel)templateData).isManyOccurs()){
+// return (JavaBeanGraphModel) collectionJavaBean;
+// }
+// }
+// }
+// }
+
+ }
+ }
+ }
+ JavaBeanGraphModel result = getCollectionRootBeanModel(collectionJavaBean);
+ if (result != null)
+ return result;
+ }
+ }
return null;
}
@@ -181,7 +224,7 @@
protected boolean isMappingValueConnection(TreeNodeConnection connection) {
AbstractSmooksGraphicalModel sourceNode = connection.getSourceNode();
Object data = sourceNode.getData();
- if(data instanceof ValueType){
+ if (data instanceof ValueType) {
return true;
}
return false;
Show replies by date