[jbosstools-commits] JBoss Tools SVN: r23270 - in branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui: META-INF and 4 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Wed Jul 7 03:04:15 EDT 2010
Author: DartPeng
Date: 2010-07-07 03:04:14 -0400 (Wed, 07 Jul 2010)
New Revision: 23270
Added:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/AbstractSmooksMultiplePageEditor.java
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/ISmooksModelProvider.java
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/SmooksConfigurationFormPage.java
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/SmooksMultiplePageEditor.java
Modified:
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/plugin.xml
branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/wizards/SmooksConfigurationFileNewWizard.java
Log:
Update Wizard and Option Form Page
Modified: branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF
===================================================================
--- branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF 2010-07-07 04:17:12 UTC (rev 23269)
+++ branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF 2010-07-07 07:04:14 UTC (rev 23270)
@@ -14,9 +14,6 @@
org.eclipse.ui.forms,
org.eclipse.wst.sse.core,
org.eclipse.wst.sse.ui,
- org.eclipse.emf,
- org.eclipse.emf.edit,
- org.eclipse.emf.edit.ui,
org.eclipse.jdt.core,
org.eclipse.jdt.ui,
org.eclipse.wst.validation,
@@ -38,7 +35,7 @@
org.eclipse.jdt.debug.ui,
org.eclipse.jdt.junit,
org.eclipse.ui.console,
- org.jboss.tools.smooks.model
+ org.jboss.tools.smooks.model;bundle-version="1.1.0"
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Modified: branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/plugin.xml
===================================================================
--- branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/plugin.xml 2010-07-07 04:17:12 UTC (rev 23269)
+++ branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/plugin.xml 2010-07-07 07:04:14 UTC (rev 23270)
@@ -5,7 +5,7 @@
<extension
point="org.eclipse.ui.editors">
<editor
- class="org.jboss.tools.smooks.configuration.editors.SmooksMultiFormEditor"
+ class="org.jboss.tools.smooks.dbm.editor.SmooksMultiplePageEditor"
contributorClass="org.jboss.tools.smooks.configuration.editors.SmooksMultiPageEditorContributor"
icon="icons/smooks-sm.gif"
id="org.jboss.tools.smooks.configuration.editors.MultiPageEditor"
Modified: branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/wizards/SmooksConfigurationFileNewWizard.java
===================================================================
--- branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/wizards/SmooksConfigurationFileNewWizard.java 2010-07-07 04:17:12 UTC (rev 23269)
+++ branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/wizards/SmooksConfigurationFileNewWizard.java 2010-07-07 07:04:14 UTC (rev 23270)
@@ -31,7 +31,7 @@
import org.eclipse.ui.part.FileEditorInput;
import org.jboss.tools.smooks.configuration.SmooksConfigurationActivator;
import org.jboss.tools.smooks.configuration.SmooksConstants;
-import org.jboss.tools.smooks.configuration.editors.SmooksMultiFormEditor;
+//import org.jboss.tools.smooks.configuration.editors.SmooksMultiFormEditor;
/**
*
@@ -139,7 +139,7 @@
FileEditorInput editorInput = new FileEditorInput(configFile);
try {
if ( fversion.equals(SmooksConstants.VERSION_1_2)) {
- page.openEditor(editorInput, SmooksMultiFormEditor.EDITOR_ID, true);
+ page.openEditor(editorInput, "org.jboss.tools.smooks.configuration.editors.MultiPageEditor", true);
}
} catch (PartInitException e) {
SmooksConfigurationActivator.getDefault().log(e);
Added: branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/AbstractSmooksMultiplePageEditor.java
===================================================================
--- branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/AbstractSmooksMultiplePageEditor.java (rev 0)
+++ branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/AbstractSmooksMultiplePageEditor.java 2010-07-07 07:04:14 UTC (rev 23270)
@@ -0,0 +1,568 @@
+/**
+ *
+ */
+package org.jboss.tools.smooks.dbm.editor;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.eclipse.core.resources.IFile;
+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.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jface.text.TextViewer;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
+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.part.FileEditorInput;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.smooks.configuration.RuntimeDependency;
+import org.jboss.tools.smooks.configuration.RuntimeMetadata;
+import org.jboss.tools.smooks.configuration.SmooksConfigurationActivator;
+import org.jboss.tools.smooks.configuration.editors.SmooksXMLEditor;
+import org.jboss.tools.smooks.editor.ISourceSynchronizeListener;
+import org.jboss.tools.smooks.editor.Messages;
+import org.jboss.tools.smooks.graphical.editors.ISmooksEditorInitListener;
+import org.jboss.tools.smooks.model.SmooksEditorModelBuilder;
+import org.jboss.tools.smooks.model.SmooksModel;
+import org.milyn.javabean.dynamic.Model;
+
+/**
+ * @author Dart
+ *
+ */
+public class AbstractSmooksMultiplePageEditor extends FormEditor implements
+ ISmooksModelProvider {
+
+ private boolean handleEMFModelChange;
+
+ private IResourceChangeListener resourceChangeListener = null;
+
+ protected StructuredTextEditor textEditor = null;
+
+ private IDocumentListener xmlDocumentTraker = null;
+
+ private Exception initSmooksModelException = null;
+
+ protected SmooksEditorModelBuilder smooksEditorModelBuilder = null;
+
+ protected List<ISmooksEditorInitListener> smooksInitListener = new ArrayList<ISmooksEditorInitListener>();
+
+ protected List<ISourceSynchronizeListener> sourceSynchronizeListener = new ArrayList<ISourceSynchronizeListener>();
+
+ protected Model<SmooksModel> smooksModel;
+
+ public AbstractSmooksMultiplePageEditor() {
+ super();
+ resourceChangeListener = new SmooksResourceTraker();
+ xmlDocumentTraker = new SmooksXMLEditorDocumentListener();
+ smooksEditorModelBuilder = new SmooksEditorModelBuilder();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
+ */
+ @Override
+ protected void addPages() {
+ textEditor = createTextEditor();
+ try {
+ int index = this.addPage(textEditor, getEditorInput());
+ setPageText(index,
+ Messages.AbstractSmooksFormEditor_Source_Page_Title);
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ int messageType = IMessageProvider.ERROR;
+ Exception exception = initSmooksModelException;
+ if (exception == null) {
+ exception = checkSmooksConfigContents(null);
+ messageType = IMessageProvider.WARNING;
+ }
+ if (exception != null) {
+ for (Iterator<?> iterator = this.smooksInitListener.iterator(); iterator
+ .hasNext();) {
+ ISmooksEditorInitListener initListener = (ISmooksEditorInitListener) iterator
+ .next();
+ initListener.initFailed(messageType, exception.getMessage());
+ }
+ }
+ }
+
+ public void addSmooksEditorInitListener(ISmooksEditorInitListener listener) {
+ this.smooksInitListener.add(listener);
+ }
+
+ public void removeSmooksEditorInitListener(
+ ISmooksEditorInitListener listener) {
+ this.smooksInitListener.remove(listener);
+ }
+
+ public void addSourceSynchronizeListener(ISourceSynchronizeListener listener) {
+ this.sourceSynchronizeListener.add(listener);
+ }
+
+ public void removeSourceSynchronizeListener(
+ ISourceSynchronizeListener listener) {
+ this.sourceSynchronizeListener.remove(listener);
+ }
+
+ @Override
+ public void init(IEditorSite site, IEditorInput input)
+ throws PartInitException {
+ RuntimeMetadata runtimeMetadata = new RuntimeMetadata();
+ String filePath = null;
+ IFile file = null;
+ if (input instanceof FileStoreEditorInput) {
+ try {
+ filePath = ((FileStoreEditorInput) input).getURI().toURL().getFile();
+ runtimeMetadata.setSmooksConfig(new File(filePath));
+ } catch (MalformedURLException e) {
+ throw new PartInitException(Messages.AbstractSmooksFormEditor_Exception_Transform_URL, e);
+ }
+ }
+ if (input instanceof IFileEditorInput) {
+ file = ((IFileEditorInput) input).getFile();
+ runtimeMetadata.setSmooksConfig(file);
+ filePath = file.getFullPath().toPortableString();
+ }
+
+ if (filePath == null)
+ throw new PartInitException(Messages.AbstractSmooksFormEditor_Exception_Cannot_Get_Input_File);
+ super.init(site, input);
+ }
+
+ public void setInput(IEditorInput input) {
+ if (getEditorInput() != null) {
+ IFile file = ((IFileEditorInput) getEditorInput()).getFile();
+ file.getWorkspace().removeResourceChangeListener(
+ resourceChangeListener);
+ }
+
+ super.setInput(input);
+
+ if (getEditorInput() != null) {
+ IFile file = ((IFileEditorInput) getEditorInput()).getFile();
+ file.getWorkspace().addResourceChangeListener(
+ resourceChangeListener);
+ setPartName(file.getName());
+ }
+
+ String filePath = null;
+
+ IFile file = null;
+
+ if (input instanceof IFileEditorInput) {
+ file = ((IFileEditorInput) input).getFile();
+ filePath = file.getFullPath().toPortableString();
+ }
+
+ // create EMF resource
+ if (file != null) {
+ try {
+ smooksModel = smooksEditorModelBuilder.readModel(file
+ .getContents());
+ } catch (Exception e) {
+ initSmooksModelException = e;
+ }
+ } else {
+ }
+
+ // if (ex == null) {
+ // if (smooksModel == null) {
+ // try {
+ // smooksResource.load(Collections.emptyMap());
+ // smooksModel = smooksResource.getContents().get(0);
+ // } catch (IOException e) {
+ //
+ // }
+ // } else {
+ // smooksResource.getContents().add(smooksModel);
+ // }
+ // }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.
+ * IProgressMonitor)
+ */
+ @Override
+ public void doSave(IProgressMonitor monitor) {
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+ try {
+ IEditorPart activeEditor = getActiveEditor();
+ if (/* this.smooksModel == null || */(activeEditor != null && activeEditor == textEditor)) {
+ textEditor.doSave(monitor);
+ /*
+ * ((BasicCommandStack)
+ * editingDomain.getCommandStack()).saveIsDone();
+ */
+
+ }
+ /*
+ * else { Map<?, ?> options = Collections.emptyMap();
+ * initSaveOptions(options); if (editingDomain != null) {
+ * ResourceSet resourceSet = editingDomain.getResourceSet();
+ * List<Resource> resourceList = resourceSet.getResources();
+ * monitor.
+ * beginTask(Messages.AbstractSmooksFormEditor_Task_Saving_File,
+ * resourceList.size());
+ *
+ * for (Iterator<Resource> iterator = resourceList.iterator();
+ * iterator.hasNext();) { handleEMFModelChange = true; Resource
+ * resource = (Resource) iterator.next(); ByteArrayOutputStream
+ * outputStream = new ByteArrayOutputStream();
+ * resource.save(outputStream, options); IResource file =
+ * SmooksUIUtils.getResource(resource); if (file.exists() && file
+ * instanceof IFile) { ByteArrayInputStream inputStream = new
+ * ByteArrayInputStream(outputStream.toByteArray());
+ * ByteArrayOutputStream newOutputStream =
+ * getFormattedXMLContentsStream(inputStream); try { ((IFile)
+ * file).setContents(new
+ * ByteArrayInputStream(newOutputStream.toByteArray()),
+ * IResource.FORCE, monitor); } catch (CoreException e) {
+ * e.printStackTrace(); } finally { if (outputStream != null) {
+ * outputStream.close(); } if (newOutputStream != null) {
+ * newOutputStream.close(); } if (inputStream != null) {
+ * inputStream.close(); } } } monitor.worked(1); }
+ * ((BasicCommandStack)
+ * editingDomain.getCommandStack()).saveIsDone();
+ * textEditor.doRevertToSaved(); } }
+ */
+ // graphChanged = false;
+ firePropertyChange(PROP_DIRTY);
+ // if (this.smooksModel != null && validator != null) {
+ // validator.startValidate(smooksModel.eResource().getContents(),
+ // editingDomain);
+ // }
+ } catch (Exception e) {
+ SmooksConfigurationActivator.log(e);
+ } finally {
+ monitor.done();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.part.EditorPart#doSaveAs()
+ */
+ @Override
+ public void doSaveAs() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
+ */
+ @Override
+ public boolean isSaveAsAllowed() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ protected Exception checkSmooksConfigContents(InputStream stream) {
+ // Check
+ Exception exception = null;
+ IFile file = null;
+ String filePath = null;
+ RuntimeMetadata runtimeMetadata = new RuntimeMetadata();
+ IEditorInput input = getEditorInput();
+ if (input instanceof FileStoreEditorInput) {
+ try {
+ filePath = ((FileStoreEditorInput) input).getURI().toURL()
+ .getFile();
+ runtimeMetadata.setSmooksConfig(new File(filePath), stream);
+ } catch (MalformedURLException e) {
+ exception = e;
+ // throw new PartInitException("Transform URL to URL error.",
+ // e);
+ }
+ }
+ if (exception == null) {
+ if (input instanceof IFileEditorInput) {
+ file = ((IFileEditorInput) input).getFile();
+ File f = new File(file.getRawLocation().toOSString().trim());
+ runtimeMetadata.setSmooksConfig(f, stream);
+ }
+
+ try {
+
+ assertConfigSupported(runtimeMetadata);
+
+ } catch (PartInitException e) {
+ exception = e;
+ }
+ }
+ return exception;
+ }
+
+ private void assertConfigSupported(RuntimeMetadata runtimeMetadata)
+ throws PartInitException {
+ List<RuntimeDependency> dependencies = runtimeMetadata
+ .getDependencies();
+
+ for (RuntimeDependency dependency : dependencies) {
+ if (!dependency.isSupportedByEditor()) {
+ java.net.URI changeToNS = dependency.getChangeToNS();
+ String errorMsg = Messages.AbstractSmooksFormEditor_Error_Unsupported
+ + dependency.getNamespaceURI()
+ + Messages.AbstractSmooksFormEditor_Error_Unsupported2;
+
+ if (changeToNS != null) {
+ errorMsg += Messages.AbstractSmooksFormEditor_Error_Update_Namespace
+ + changeToNS
+ + Messages.AbstractSmooksFormEditor_Error_Update_Namespace2;
+ }
+
+ throw new PartInitException(errorMsg);
+ }
+ }
+ }
+
+ protected StructuredTextEditor createTextEditor() {
+ SmooksXMLEditor xmlEditor = new SmooksXMLEditor() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.jboss.tools.smooks.configuration.editors.SmooksXMLEditor#
+ * doSetInput(org.eclipse.ui.IEditorInput)
+ */
+ @Override
+ public void doSetInput(IEditorInput input) throws CoreException {
+ TextViewer viewer = getTextViewer();
+ if (viewer != null) {
+ IDocument document = viewer.getDocument();
+ if (document != null) {
+ document.removeDocumentListener(xmlDocumentTraker);
+ }
+ }
+ super.doSetInput(input);
+ viewer = getTextViewer();
+ if (viewer != null) {
+ IDocument document = viewer.getDocument();
+ if (document != null) {
+ document.addDocumentListener(xmlDocumentTraker);
+ }
+ }
+ }
+
+ public void createPartControl(Composite parent) {
+ super.createPartControl(parent);
+ getTextViewer().getDocument().addDocumentListener(
+ xmlDocumentTraker);
+
+ }
+
+ };
+ return xmlEditor;
+ }
+
+ public void createNewModelViaTextPage() {
+ IDocumentProvider dp = textEditor.getDocumentProvider();
+ if (dp == null)
+ return;
+ Exception exception = null;
+ int messageType = IMessageProvider.NONE;
+ IDocument document = dp.getDocument(textEditor.getEditorInput());
+ String conents = document.get();
+ InputStream stream = new ByteArrayInputStream(conents.getBytes());
+ exception = checkSmooksConfigContents(stream);
+ if (exception != null)
+ messageType = IMessageProvider.WARNING;
+ if (exception == null) {
+ try {
+ stream = new ByteArrayInputStream(conents.getBytes());
+ this.smooksModel = smooksEditorModelBuilder.readModel(stream);
+ } catch (Exception e) {
+ smooksModel = null;
+ exception = e;
+ messageType = IMessageProvider.ERROR;
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ // setPlatformVersion(SmooksUIUtils.judgeSmooksPlatformVersion(smooksModel));
+ // judgeInputReader();
+ for (Iterator<?> iterator = this.sourceSynchronizeListener.iterator(); iterator
+ .hasNext();) {
+ ISourceSynchronizeListener l = (ISourceSynchronizeListener) iterator
+ .next();
+ try {
+ l.sourceChange(smooksModel);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ String message = null;
+ if (exception != null) {
+ message = exception.getMessage();
+ }
+ if (message == null) {
+ message = Messages.AbstractSmooksFormEditor_Error_Unknown;
+ }
+ for (Iterator<?> iterator = this.smooksInitListener.iterator(); iterator
+ .hasNext();) {
+ ISmooksEditorInitListener initListener = (ISmooksEditorInitListener) iterator
+ .next();
+ initListener.initFailed(messageType, message);
+ }
+ }
+
+ public void handleDocumentChange() {
+ createNewModelViaTextPage();
+ }
+
+ public class SmooksXMLEditorDocumentListener implements IDocumentListener {
+ protected Timer timer = new Timer();
+ protected TimerTask timerTask;
+
+ public void documentAboutToBeChanged(DocumentEvent documentEvent) {
+ // Ingore
+ }
+
+ public void documentChanged(final DocumentEvent documentEvent) {
+ try {
+ // This is need for the Properties view.
+ //
+ // setSelection(StructuredSelection.EMPTY);
+
+ if (timerTask != null) {
+ timerTask.cancel();
+ }
+
+ if (handleEMFModelChange) {
+ handleEMFModelChange = false;
+ } else {
+ timerTask = new TimerTask() {
+ @Override
+ public void run() {
+ getSite().getShell().getDisplay()
+ .asyncExec(new Runnable() {
+ public void run() {
+ handleDocumentChange();
+ }
+ });
+ }
+ };
+
+ timer.schedule(timerTask, 1000);
+ }
+ } catch (Exception exception) {
+ SmooksConfigurationActivator.log(exception);
+ }
+ }
+ }
+
+ public class SmooksResourceTraker implements IResourceChangeListener,
+ IResourceDeltaVisitor {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.resources.IResourceChangeListener#resourceChanged
+ * (org.eclipse.core.resources.IResourceChangeEvent)
+ */
+ public void resourceChanged(IResourceChangeEvent event) {
+ IResourceDelta delta = event.getDelta();
+ try {
+ if (delta != null)
+ delta.accept(this);
+ } catch (CoreException exception) {
+ }
+ }
+
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ if (delta == null
+ || !delta.getResource().equals(
+ ((IFileEditorInput) getEditorInput()).getFile()))
+ return true;
+
+ if (delta.getKind() == IResourceDelta.REMOVED) {
+ Display display = getSite().getShell().getDisplay();
+ if ((IResourceDelta.MOVED_TO & delta.getFlags()) == 0) { // if
+ // the
+ // file
+ // was
+ // deleted
+ // NOTE: The case where an open, unsaved file is deleted is
+ // being handled by the
+ // PartListener added to the Workbench in the initialize()
+ // method.
+ display.asyncExec(new Runnable() {
+ public void run() {
+ // if (!isDirty())
+ closeEditor(false);
+ }
+ });
+ } else { // else if it was moved or renamed
+ final IFile newFile = ResourcesPlugin.getWorkspace()
+ .getRoot().getFile(delta.getMovedToPath());
+ display.asyncExec(new Runnable() {
+ public void run() {
+ // try {
+ // ((SmooksXMLEditor) textEditor).doSetInput(new
+ // FileEditorInput(newFile));
+ // } catch (CoreException e) {
+ // e.printStackTrace();
+ // }
+ setInput(new FileEditorInput(newFile));
+ }
+ });
+ }
+ }
+ return false;
+ }
+ }
+
+ private void closeEditor(boolean forceSave) {
+ this.close(forceSave);
+ }
+
+ public Model<SmooksModel> getSmooksModel() {
+ return smooksModel;
+ }
+
+}
Property changes on: branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/AbstractSmooksMultiplePageEditor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/ISmooksModelProvider.java
===================================================================
--- branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/ISmooksModelProvider.java (rev 0)
+++ branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/ISmooksModelProvider.java 2010-07-07 07:04:14 UTC (rev 23270)
@@ -0,0 +1,15 @@
+/**
+ *
+ */
+package org.jboss.tools.smooks.dbm.editor;
+
+import org.jboss.tools.smooks.model.SmooksModel;
+import org.milyn.javabean.dynamic.Model;
+
+/**
+ * @author Dart
+ *
+ */
+public interface ISmooksModelProvider {
+ Model<SmooksModel> getSmooksModel();
+}
Property changes on: branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/ISmooksModelProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/SmooksConfigurationFormPage.java
===================================================================
--- branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/SmooksConfigurationFormPage.java (rev 0)
+++ branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/SmooksConfigurationFormPage.java 2010-07-07 07:04:14 UTC (rev 23270)
@@ -0,0 +1,333 @@
+/**
+ *
+ */
+package org.jboss.tools.smooks.dbm.editor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.forms.IFormColors;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.IMessage;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.forms.widgets.ScrolledPageBook;
+import org.eclipse.ui.forms.widgets.Section;
+import org.jboss.tools.smooks.configuration.SmooksConstants;
+import org.jboss.tools.smooks.configuration.editors.Messages;
+import org.jboss.tools.smooks.configuration.editors.uitls.SmooksUIUtils;
+import org.jboss.tools.smooks.editor.ISourceSynchronizeListener;
+import org.jboss.tools.smooks.graphical.editors.ISmooksEditorInitListener;
+import org.jboss.tools.smooks.graphical.editors.SmooksMessage;
+import org.jboss.tools.smooks.model.core.Param;
+import org.jboss.tools.smooks.model.core.Params;
+
+/**
+ * @author Dart
+ *
+ */
+public class SmooksConfigurationFormPage extends FormPage implements ISmooksEditorInitListener , ISourceSynchronizeListener {
+
+ private String currentMessage = null;
+ private ISmooksModelProvider smooksModelProvider;
+// private ModelPanelCreator defaultSettingPanelCreator;
+ private Section globalParamSection;
+ private Section settingSection;
+ protected boolean lockEventFire = false;
+
+ private Combo streamFilterTypeCombo;
+ private Button defaultSerializationOnCheckbox;
+ private Combo versionCombo;
+ private int currentMessageType;
+
+ public SmooksConfigurationFormPage(FormEditor editor, String id,
+ String title, ISmooksModelProvider provider) {
+ super(editor, id, title);
+ this.smooksModelProvider = provider;
+ }
+
+ public SmooksConfigurationFormPage(String id, String title, ISmooksModelProvider provider) {
+ super(id, title);
+ this.smooksModelProvider = provider;
+ }
+
+ protected void createFormContent(IManagedForm managedForm) {
+ final ScrolledForm form = managedForm.getForm();
+ FormToolkit toolkit = managedForm.getToolkit();
+ toolkit.decorateFormHeading(form.getForm());
+ String title = getTitle();
+ form.setText(title);
+ GridLayout gl = new GridLayout();
+ gl.marginHeight = 0;
+ gl.marginWidth = 0;
+ form.getBody().setLayout(gl);
+
+ ScrolledPageBook pageBook = new ScrolledPageBook(form.getBody());
+ pageBook.setBackground(toolkit.getColors().getBackground());
+ Composite mainComposite = pageBook.createPage(pageBook);
+ pageBook.showPage(pageBook);
+
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ pageBook.setLayoutData(gd);
+
+ GridLayout mgl = new GridLayout();
+ mgl.numColumns = 2;
+ mgl.horizontalSpacing = 20;
+ mainComposite.setLayout(mgl);
+
+ settingSection = toolkit.createSection(mainComposite, Section.TITLE_BAR);
+ settingSection.setLayout(new FillLayout());
+ settingSection.setText(Messages.SmooksConfigurationOverviewPage_ConfigurationSectionTitle);
+ Composite settingComposite = toolkit.createComposite(settingSection);
+ settingSection.setClient(settingComposite);
+ gd = new GridData();
+ gd.widthHint = 500;
+ gd.verticalAlignment = GridData.BEGINNING;
+ settingSection.setLayoutData(gd);
+
+ GridLayout sgl = new GridLayout();
+ settingComposite.setLayout(sgl);
+ sgl.numColumns = 2;
+
+ createSettingSection(settingComposite, toolkit);
+
+ globalParamSection = toolkit.createSection(mainComposite, Section.TITLE_BAR | Section.TWISTIE
+ | Section.EXPANDED);
+ globalParamSection.setText(Messages.SmooksConfigurationOverviewPage_FilterSettingSectionTitle);
+ globalParamSection.setLayout(new FillLayout());
+ Composite globalParamComposite = toolkit.createComposite(globalParamSection);
+ globalParamSection.setClient(globalParamComposite);
+ gd = new GridData();
+ gd.verticalAlignment = GridData.BEGINNING;
+ gd.widthHint = 500;
+ globalParamSection.setLayoutData(gd);
+
+ GridLayout gpgl = new GridLayout();
+ globalParamComposite.setLayout(gpgl);
+ gpgl.numColumns = 2;
+
+ createGlobalParamterSection(globalParamComposite, toolkit);
+
+
+ updateFormHeader();
+ }
+
+ protected void updateFormHeader() {
+ if (currentMessageType == IMessageProvider.NONE) {
+ if (this.getManagedForm() != null) {
+ getManagedForm().getMessageManager().removeAllMessages();
+ getManagedForm().getMessageManager().update();
+
+ streamFilterTypeCombo.setEnabled(true);
+ defaultSerializationOnCheckbox.setEnabled(true);
+ }
+ } else {
+ if (this.getManagedForm() != null) {
+ streamFilterTypeCombo.setEnabled(false);
+ defaultSerializationOnCheckbox.setEnabled(false);
+ String[] messages = currentMessage.split("\n"); //$NON-NLS-1$
+ List<IMessage> messageList = new ArrayList<IMessage>();
+ for (int i = 0; i < messages.length; i++) {
+ String message = messages[i];
+ if (message != null)
+ message.trim();
+ if (message.length() == 0) {
+ continue;
+ }
+ messageList.add(new SmooksMessage(currentMessageType, message));
+ }
+ String mainMessage = null;
+ if (messageList.isEmpty()) {
+ mainMessage = currentMessage;
+ } else {
+ mainMessage = messageList.get(0).getMessage();
+ }
+ this.getManagedForm().getForm().getForm().setMessage(mainMessage, currentMessageType,
+ messageList.toArray(new IMessage[] {}));
+ }
+ }
+ }
+
+ private void createSettingSection(Composite settingComposite, FormToolkit toolkit) {
+ toolkit.createLabel(settingComposite, Messages.SmooksConfigurationOverviewPage_VersionLabel).setForeground(
+ toolkit.getColors().getColor(IFormColors.TITLE));
+ int type = SWT.BORDER;
+// if (SmooksUIUtils.isLinuxOS()) {
+// type = SWT.BORDER;
+// }
+ versionCombo = new Combo(settingComposite, type | SWT.READ_ONLY);
+ versionCombo.setEnabled(false);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ versionCombo.setLayoutData(gd);
+ for (int i = 0; i < SmooksConstants.SMOOKS_VERSIONS.length; i++) {
+ String version = SmooksConstants.SMOOKS_VERSIONS[i];
+ versionCombo.add(version);
+ }
+
+ String version = getSmooksVersion();
+ if (version != null)
+ versionCombo.setText(version);
+ versionCombo.addModifyListener(new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ // if (smooksModelProvider != null) {
+ // smooksModelProvider.getSmooksGraphicsExt().setPlatformVersion(v);
+ // }
+ }
+ });
+
+ toolkit.paintBordersFor(settingComposite);
+ }
+
+ private String getSmooksVersion() {
+ return "1.1";
+ }
+
+
+ private void createGlobalParamterSection(Composite globalParamComposite, FormToolkit toolkit) {
+ if (smooksModelProvider != null) {
+
+ toolkit.createLabel(globalParamComposite, Messages.SmooksConfigurationOverviewPage_FilterTypeLabel)
+ .setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
+ GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false);
+ streamFilterTypeCombo = new Combo(globalParamComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
+ streamFilterTypeCombo.setItems(new String[] { "SAX", "DOM" }); //$NON-NLS-1$ //$NON-NLS-2$
+ streamFilterTypeCombo.setLayoutData(gd);
+
+ toolkit.createLabel(globalParamComposite, Messages.SmooksConfigurationOverviewPage_SerializationLabel)
+ .setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
+ gd = new GridData(SWT.FILL, SWT.NONE, true, false);
+ defaultSerializationOnCheckbox = toolkit.createButton(globalParamComposite, null, SWT.CHECK); //$NON-NLS-1$
+ defaultSerializationOnCheckbox.setLayoutData(gd);
+
+ initGlobalSettingControls();
+
+ toolkit.paintBordersFor(globalParamComposite);
+
+ streamFilterTypeCombo.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(SelectionEvent e) {
+ if (lockEventFire)
+ return;
+ String value = streamFilterTypeCombo.getText();
+ updateGlobalProperty("stream.filter.type", value); //$NON-NLS-1$
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ });
+
+ defaultSerializationOnCheckbox.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ if (lockEventFire)
+ return;
+ String value = Boolean.toString(defaultSerializationOnCheckbox.getSelection());
+ updateGlobalProperty("default.serialization.on", value); //$NON-NLS-1$
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ widgetDefaultSelected(e);
+ }
+ });
+ }
+
+ }
+
+ protected Params getParams(){
+ if(smooksModelProvider != null){
+ return smooksModelProvider.getSmooksModel().getModelRoot().getParams();
+ }
+ return null;
+ }
+
+ protected void initGlobalSettingControls() {
+ Params m = getParams();
+ if (m != null) {
+ List<Param> parmList = m.getParams();
+ for (int i = 0; i < parmList.size(); i++) {
+ Param param = (Param) parmList.get(i);
+ if (param.getName().equals("stream.filter.type")) { //$NON-NLS-1$
+ streamFilterTypeCombo.setText(param.getValue());
+ } else if (param.getName().equals("default.serialization.on")) { //$NON-NLS-1$
+ Boolean boolValue = Boolean.valueOf(param.getValue());
+ defaultSerializationOnCheckbox.setSelection(boolValue.booleanValue());
+ }
+ }
+ } else { // set defaults
+ streamFilterTypeCombo.setText("SAX"); //$NON-NLS-1$
+ defaultSerializationOnCheckbox.setSelection(true);
+ }
+ }
+
+ private void updateGlobalProperty(String propertyID, String value) {
+ boolean foundProperty = false;
+ if (getSmooksVersion() == null) {
+ return;
+ }
+ Params parent = getParams();
+ Param param = null;
+ Param newparam = null;
+ if (parent != null) {
+ List<?> parmList = parent.getParams();
+ for (int i = 0; i < parmList.size(); i++) {
+ param = (Param) parmList.get(i);
+ if (param.getName().equals(propertyID)) {
+ param.setValue(value);
+ foundProperty = true;
+ break;
+ }
+ }
+ }
+ if(!foundProperty){
+ newparam = new Param();
+ newparam.setName(propertyID);
+ newparam.setValue(value);
+ parent.getParams().add(newparam);
+ }
+ }
+
+ public void initFailed(int messageType, String message) {
+
+ }
+
+ public void sourceChange(Object model) {
+ lockEventFire = true;
+ if (streamFilterTypeCombo == null || defaultSerializationOnCheckbox == null || versionCombo == null) {
+ lockEventFire = false;
+ return;
+ }
+ streamFilterTypeCombo.setEnabled(true);
+ defaultSerializationOnCheckbox.setEnabled(true);
+ String version = getSmooksVersion();
+ if (version == null)
+ version = ""; //$NON-NLS-1$
+ versionCombo.setText(version);
+
+ if (model == null) {
+ // the file was broken
+ streamFilterTypeCombo.setEnabled(false);
+
+ defaultSerializationOnCheckbox.setEnabled(false);
+ defaultSerializationOnCheckbox.setSelection(false);
+ } else {
+ initGlobalSettingControls();
+ }
+ lockEventFire = false;
+ }
+}
Property changes on: branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/SmooksConfigurationFormPage.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/SmooksMultiplePageEditor.java
===================================================================
--- branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/SmooksMultiplePageEditor.java (rev 0)
+++ branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/SmooksMultiplePageEditor.java 2010-07-07 07:04:14 UTC (rev 23270)
@@ -0,0 +1,35 @@
+/**
+ *
+ */
+package org.jboss.tools.smooks.dbm.editor;
+
+import org.eclipse.ui.PartInitException;
+import org.jboss.tools.smooks.configuration.editors.Messages;
+
+/**
+ * @author Dart
+ *
+ */
+public class SmooksMultiplePageEditor extends AbstractSmooksMultiplePageEditor {
+
+ private SmooksConfigurationFormPage optionsPage;
+
+ @Override
+ protected void addPages() {
+ optionsPage = createSmooksConfigurationOverviewPage();
+ addSourceSynchronizeListener(optionsPage);
+ addSmooksEditorInitListener(optionsPage);
+ try {
+ int index = this.addPage(optionsPage);
+ setPageText(index, Messages.SmooksMultiFormEditor_opetiontab_label);
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ super.addPages();
+ }
+
+ private SmooksConfigurationFormPage createSmooksConfigurationOverviewPage() {
+ return new SmooksConfigurationFormPage(this,
+ "options_page", Messages.SmooksMultiFormEditor_optinepage_name, this); //$NON-NLS-1$
+ }
+}
Property changes on: branches/smooks-dmb/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/dbm/editor/SmooksMultiplePageEditor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the jbosstools-commits
mailing list