Author: DartPeng
Date: 2009-10-28 05:35:03 -0400 (Wed, 28 Oct 2009)
New Revision: 18336
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edi/EDIDataParser.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/ProjectClassLoader.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/ClassFieldEditorValidator.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/SelectorValidator.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/SmooksModelValidator.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/gef/tree/figures/GraphAnimation.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/actions/AutoLayoutAction.java
trunk/smooks/tests/org.jboss.tools.smooks.core.test/src/org/jboss/tools/smooks/test/openeditor/AbstractSmooksEditorTestcase.java
Log:
JBIDE-4217
Add a test case to open the Smooks config file automatically
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF 2009-10-28
09:32:04 UTC (rev 18335)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF 2009-10-28
09:35:03 UTC (rev 18336)
@@ -38,9 +38,14 @@
Bundle-Vendor: %providerName
Bundle-ClassPath: libs/dom4j-1.6.1.jar,
.
-Export-Package: org.jboss.tools.smooks.configuration.editors,
+Export-Package: org.jboss.tools.smooks.configuration,
+ org.jboss.tools.smooks.configuration.editors,
org.jboss.tools.smooks.configuration.editors.csv,
org.jboss.tools.smooks.configuration.editors.edi,
org.jboss.tools.smooks.configuration.editors.javabean,
org.jboss.tools.smooks.configuration.editors.uitls,
- org.jboss.tools.smooks.configuration.editors.xml
+ org.jboss.tools.smooks.configuration.editors.xml,
+ org.jboss.tools.smooks.configuration.editors_10,
+ org.jboss.tools.smooks.edimap.editor,
+ org.jboss.tools.smooks.editor,
+ org.jboss.tools.smooks.graphical.editors
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edi/EDIDataParser.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edi/EDIDataParser.java 2009-10-28
09:32:04 UTC (rev 18335)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edi/EDIDataParser.java 2009-10-28
09:35:03 UTC (rev 18336)
@@ -29,6 +29,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.ui.ide.IDE;
@@ -225,6 +226,7 @@
URL ur = bundle.getEntry("/src" + mappingModel);
if (ur != null) {
try {
+ ur = FileLocator.resolve(ur);
modelPath = ur.toURI().toString();
} catch (URISyntaxException e) {
e.printStackTrace();
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/ProjectClassLoader.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/ProjectClassLoader.java 2009-10-28
09:32:04 UTC (rev 18335)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/ProjectClassLoader.java 2009-10-28
09:35:03 UTC (rev 18336)
@@ -40,6 +40,9 @@
private static URL[] getURLSFromProject(IJavaProject project,
URL[] extraUrls, boolean cludeRequiredProject)
throws JavaModelException {
+ if(project == null || !project.exists()){
+ return new URL[]{};
+ }
List<URL> list = new ArrayList<URL>();
if (null != extraUrls) {
for (int i = 0; i < extraUrls.length; i++) {
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java 2009-10-28
09:32:04 UTC (rev 18335)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java 2009-10-28
09:35:03 UTC (rev 18336)
@@ -32,7 +32,10 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.common.util.URI;
@@ -1004,16 +1007,16 @@
"Browse", new IFieldDialog() {
public Object open(Shell shell) {
SelectorCreationDialog dialog = new SelectorCreationDialog(shell, extType,
currentEditorPart);
- try{
- if (dialog.open() == Dialog.OK) {
- Object currentSelection = dialog.getCurrentSelection();
- SelectorAttributes sa = dialog.getSelectorAttributes();
- if (currentSelection instanceof IXMLStructuredObject) {
- String s = SmooksUIUtils.generatePath((IXMLStructuredObject) currentSelection,
sa);
- return s;
+ try {
+ if (dialog.open() == Dialog.OK) {
+ Object currentSelection = dialog.getCurrentSelection();
+ SelectorAttributes sa = dialog.getSelectorAttributes();
+ if (currentSelection instanceof IXMLStructuredObject) {
+ String s = SmooksUIUtils.generatePath((IXMLStructuredObject) currentSelection,
sa);
+ return s;
+ }
}
- }
- }catch(Exception e){
+ } catch (Exception e) {
e.printStackTrace();
}
return null;
@@ -2444,8 +2447,8 @@
return false;
}
- public static List<InputType> recordInputDataInfomation(EditingDomain domain,
InputType input, SmooksGraphicsExtType extType,
- String type, String path, Properties properties) {
+ public static List<InputType> recordInputDataInfomation(EditingDomain domain,
InputType input,
+ SmooksGraphicsExtType extType, String type, String path, Properties properties) {
List<InputType> inputTypeList = new ArrayList<InputType>();
if (type != null && path != null && extType != null && domain
!= null) {
String[] values = path.split(";");
@@ -2498,7 +2501,7 @@
// SmooksConfigurationActivator.getDefault().log(e);
// }
}
-
+
return inputTypeList;
}
@@ -2911,4 +2914,23 @@
}
return inputType;
}
+
+ public static boolean isSmooksFile(IFile file) {
+ if(file.getName().indexOf(".xml") != -1) return true;
+ IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
+ IContentType[] types = contentTypeManager.findContentTypesFor(file.getName());
+ for (IContentType contentType : types) {
+ if
(contentType.equals(contentTypeManager.getContentType("org.jboss.tools.smooks.ui.smooks.contentType")))
{
+ return true;
+ }
+ if
(contentType.equals(contentTypeManager.getContentType("org.jboss.tools.smooks.ui.edimap.contentType")))
{
+ return true;
+ }
+ if (contentType
+ .equals(contentTypeManager.getContentType("org.jboss.tools.smooks.ui.smooks1_0.contentType")))
{
+ return true;
+ }
+ }
+ return false;
+ }
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/ClassFieldEditorValidator.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/ClassFieldEditorValidator.java 2009-10-28
09:32:04 UTC (rev 18335)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/ClassFieldEditorValidator.java 2009-10-28
09:35:03 UTC (rev 18336)
@@ -52,6 +52,7 @@
return classLoader;
}
IResource resource = SmooksUIUtils.getResource(obj);
+ if(resource == null) return null;
try {
classLoader = new ProjectClassLoader(JavaCore.create(resource.getProject()));
} catch (JavaModelException e) {
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/SelectorValidator.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/SelectorValidator.java 2009-10-28
09:32:04 UTC (rev 18335)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/SelectorValidator.java 2009-10-28
09:35:03 UTC (rev 18336)
@@ -134,6 +134,8 @@
if (r instanceof IFile) {
file = (IFile) r;
}
+ if (file == null)
+ return;
final FileEditorInput input = new FileEditorInput(file);
final SmooksResourceListType finalList = listType;
Display dis = SmooksConfigurationActivator.getDefault().getWorkbench().getDisplay();
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/SmooksModelValidator.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/SmooksModelValidator.java 2009-10-28
09:32:04 UTC (rev 18335)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/validate/SmooksModelValidator.java 2009-10-28
09:35:03 UTC (rev 18336)
@@ -164,16 +164,20 @@
List<Diagnostic> list = new ArrayList<Diagnostic>();
list.add(diagnostic);
- for (Iterator<?> iterator = this.validatorList.iterator(); iterator.hasNext();)
{
- ISmooksValidator validator = (ISmooksValidator) iterator.next();
- validator.initValidator(selectedObjects, domain);
- List<Diagnostic> d = validator.validate(selectedObjects, domain);
- if (d != null) {
- for (Iterator<?> iterator2 = d.iterator(); iterator2.hasNext();) {
- Diagnostic diagnostic2 = (Diagnostic) iterator2.next();
- ((BasicDiagnostic) diagnostic).add(diagnostic2);
+ try {
+ for (Iterator<?> iterator = this.validatorList.iterator(); iterator.hasNext();)
{
+ ISmooksValidator validator = (ISmooksValidator) iterator.next();
+ validator.initValidator(selectedObjects, domain);
+ List<Diagnostic> d = validator.validate(selectedObjects, domain);
+ if (d != null) {
+ for (Iterator<?> iterator2 = d.iterator(); iterator2.hasNext();) {
+ Diagnostic diagnostic2 = (Diagnostic) iterator2.next();
+ ((BasicDiagnostic) diagnostic).add(diagnostic2);
+ }
}
}
+ } catch (Exception e) {
+
}
return list;
}
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 2009-10-28
09:32:04 UTC (rev 18335)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/AbstractSmooksFormEditor.java 2009-10-28
09:35:03 UTC (rev 18336)
@@ -3,6 +3,7 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -48,6 +49,7 @@
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.jboss.tools.smooks.configuration.SmooksConfigurationActivator;
@@ -484,9 +486,33 @@
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
- IFile file = ((IFileEditorInput) input).getFile();
- Resource smooksResource = new
SmooksResourceFactoryImpl().createResource(URI.createPlatformResourceURI(file
- .getFullPath().toPortableString(), false));
+ String filePath = null;
+ String partName = "smooks editor";
+ IFile file = null;
+ if (input instanceof FileStoreEditorInput) {
+ try {
+ filePath = ((FileStoreEditorInput) input).getURI().toURL().getFile();
+ } catch (MalformedURLException e) {
+ throw new PartInitException("Transform URL to URL error.", e);
+ }
+ }
+ if (input instanceof IFileEditorInput) {
+ file = ((IFileEditorInput) input).getFile();
+ filePath = file.getFullPath().toPortableString();
+ partName = file.getName();
+ }
+
+ if (filePath == null)
+ throw new PartInitException("Can't get the input file");
+
+ Resource smooksResource = null;
+
+ if (file != null) {
+ smooksResource = new
SmooksResourceFactoryImpl().createResource(URI.createPlatformResourceURI(filePath,
+ false));
+ } else {
+ smooksResource = new
SmooksResourceFactoryImpl().createResource(URI.createFileURI(filePath));
+ }
try {
smooksResource.load(Collections.emptyMap());
smooksModel = smooksResource.getContents().get(0);
@@ -504,7 +530,7 @@
// smooks config file
// create new one for it
- setPartName(file.getName());
+ setPartName(partName);
smooksGraphicsExt = createSmooksGraphcsExtType(smooksModel);
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/figures/GraphAnimation.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/figures/GraphAnimation.java 2009-10-28
09:32:04 UTC (rev 18335)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/figures/GraphAnimation.java 2009-10-28
09:35:03 UTC (rev 18336)
@@ -122,7 +122,7 @@
}
try {
- Thread.sleep(10);
+ Thread.sleep(5);
Thread.yield();
} catch (InterruptedException e) {
e.printStackTrace();
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/actions/AutoLayoutAction.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/actions/AutoLayoutAction.java 2009-10-28
09:32:04 UTC (rev 18335)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/actions/AutoLayoutAction.java 2009-10-28
09:35:03 UTC (rev 18336)
@@ -10,16 +10,25 @@
******************************************************************************/
package org.jboss.tools.smooks.graphical.actions;
+import java.io.File;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
import org.eclipse.gef.ui.actions.SelectionAction;
import org.eclipse.ui.IWorkbenchPart;
+import org.jboss.tools.smooks.configuration.editors.uitls.SmooksUIUtils;
import org.jboss.tools.smooks.graphical.editors.SmooksGraphicalEditorPart;
import org.jboss.tools.smooks.graphical.editors.editparts.IAutoLayout;
/**
* @author Dart
- *
+ *
*/
-public class AutoLayoutAction extends SelectionAction{
+public class AutoLayoutAction extends SelectionAction {
public static final String ID = "_smooks_auto_layout";
@@ -30,9 +39,10 @@
public AutoLayoutAction(IWorkbenchPart part) {
super(part);
}
-
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.gef.ui.actions.WorkbenchPartAction#init()
*/
@Override
@@ -41,28 +51,78 @@
this.setText("Auto Layout");
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
*/
@Override
protected boolean calculateEnabled() {
IWorkbenchPart part = this.getWorkbenchPart();
- if(part instanceof SmooksGraphicalEditorPart){
- IAutoLayout layout = ((SmooksGraphicalEditorPart)part).getAutoLayout();
+ if (part instanceof SmooksGraphicalEditorPart) {
+ IAutoLayout layout = ((SmooksGraphicalEditorPart) part).getAutoLayout();
return (layout != null);
}
return false;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
+// if (false) {
+// IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject("test");
+// File file = project.getLocation().toFile();
+// File[] children = file.listFiles();
+// for (int i = 0; i < children.length; i++) {
+// File child = children[i];
+// copySmooksFile(child, project);
+// }
+// }
IWorkbenchPart part = this.getWorkbenchPart();
- if(part instanceof SmooksGraphicalEditorPart){
- ((SmooksGraphicalEditorPart)part).autoLayout(true);
+ if (part instanceof SmooksGraphicalEditorPart) {
+ ((SmooksGraphicalEditorPart) part).autoLayout(true);
}
}
-
+
+ /**
+ * @deprecated
+ * @param file
+ * @param parent
+ */
+ private void copySmooksFile(File file, IContainer parent) {
+ if (file.exists()) {
+ if (file.isFile()) {
+ IFile ifile = parent.getFile(new Path(file.getName()));
+ if (ifile.exists() && SmooksUIUtils.isSmooksFile(ifile)) {
+ IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject("validation-test");
+ IFolder folder = project.getFolder("src");
+ IFile newFile = folder.getFile(parent.getName()+ "_" + ifile.getName());
+ try {
+ if (newFile.exists()) {
+ newFile.setContents(ifile.getContents(), true, false, null);
+ } else {
+ newFile.create(ifile.getContents(), true, null);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ if (file.isDirectory()) {
+ IContainer container = parent.getFolder(new Path(file.getName()));
+ if (container.exists()) {
+ File[] files = file.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ File file2 = files[i];
+ copySmooksFile(file2, container);
+ }
+ }
+ }
+ }
+ }
+
}
Modified:
trunk/smooks/tests/org.jboss.tools.smooks.core.test/src/org/jboss/tools/smooks/test/openeditor/AbstractSmooksEditorTestcase.java
===================================================================
---
trunk/smooks/tests/org.jboss.tools.smooks.core.test/src/org/jboss/tools/smooks/test/openeditor/AbstractSmooksEditorTestcase.java 2009-10-28
09:32:04 UTC (rev 18335)
+++
trunk/smooks/tests/org.jboss.tools.smooks.core.test/src/org/jboss/tools/smooks/test/openeditor/AbstractSmooksEditorTestcase.java 2009-10-28
09:35:03 UTC (rev 18336)
@@ -37,6 +37,10 @@
protected List<IEditorPart> editorList = new ArrayList<IEditorPart>();
protected IProject testProject = null;
+
+ public void test(){
+
+ }
private void setUpEnvironment() throws CoreException {
if (getTestProjectName() != null) {