Author: DartPeng
Date: 2009-04-03 13:13:22 -0400 (Fri, 03 Apr 2009)
New Revision: 14504
Modified:
workspace/dart/smooksConfigurationsEditor/org.jboss.tools.smooks.configuration/src/org/jboss/tools/smooks/configuration/editors/SmooksConfigurationFormPage.java
workspace/dart/smooksConfigurationsEditor/org.jboss.tools.smooks.configuration/src/org/jboss/tools/smooks/configuration/editors/SmooksMasterDetailBlock.java
workspace/dart/smooksConfigurationsEditor/org.jboss.tools.smooks.configuration/src/org/jboss/tools/smooks/configuration/editors/SmooksMultiFormEditor.java
Log:
Modified:
workspace/dart/smooksConfigurationsEditor/org.jboss.tools.smooks.configuration/src/org/jboss/tools/smooks/configuration/editors/SmooksConfigurationFormPage.java
===================================================================
---
workspace/dart/smooksConfigurationsEditor/org.jboss.tools.smooks.configuration/src/org/jboss/tools/smooks/configuration/editors/SmooksConfigurationFormPage.java 2009-04-03
16:29:01 UTC (rev 14503)
+++
workspace/dart/smooksConfigurationsEditor/org.jboss.tools.smooks.configuration/src/org/jboss/tools/smooks/configuration/editors/SmooksConfigurationFormPage.java 2009-04-03
17:13:22 UTC (rev 14504)
@@ -52,6 +52,10 @@
form.getBody().setLayout(gridLayout);
}
+ public void setSmooksModel(Object model){
+ masterDetailBlock.setSmooksModel(model);
+ }
+
public void setSelectionToViewer(final Collection<?> collection){
if(masterDetailBlock != null && masterDetailBlock.getSmooksTreeViewer() !=
null){
// I don't know if this should be run this deferred
Modified:
workspace/dart/smooksConfigurationsEditor/org.jboss.tools.smooks.configuration/src/org/jboss/tools/smooks/configuration/editors/SmooksMasterDetailBlock.java
===================================================================
---
workspace/dart/smooksConfigurationsEditor/org.jboss.tools.smooks.configuration/src/org/jboss/tools/smooks/configuration/editors/SmooksMasterDetailBlock.java 2009-04-03
16:29:01 UTC (rev 14503)
+++
workspace/dart/smooksConfigurationsEditor/org.jboss.tools.smooks.configuration/src/org/jboss/tools/smooks/configuration/editors/SmooksMasterDetailBlock.java 2009-04-03
17:13:22 UTC (rev 14504)
@@ -12,7 +12,6 @@
import java.util.List;
-import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.BasicFeatureMapEntry;
@@ -106,11 +105,10 @@
}
protected void createSmooksTreeViewer(FormToolkit tool, final IManagedForm managedForm,
- Composite rootMainControl) {
- configurationSection = tool.createSection(rootMainControl, Section.TITLE_BAR
- | Section.DESCRIPTION);
+ Composite rootMainControl) {
+ configurationSection = tool.createSection(rootMainControl, Section.TITLE_BAR |
Section.DESCRIPTION);
configurationSection
- .setDescription("Define Smooks stuffes for configuration file in the following
section.");
+ .setDescription("Define Smooks stuffes for configuration file in the following
section.");
configurationSection.setText("All Smooks Stuffes");
sectionPart = new SectionPart(configurationSection);
managedForm.addPart(sectionPart);
@@ -130,23 +128,19 @@
tableComposite.setLayout(fillLayout);
smooksTreeViewer = new TreeViewer(tableComposite, SWT.NONE);
smooksTreeViewer.setContentProvider(new AdapterFactoryContentProvider(editingDomain
- .getAdapterFactory()));
- smooksTreeViewer.setLabelProvider(new AdapterFactoryLabelProvider(editingDomain
- .getAdapterFactory()));
+ .getAdapterFactory()));
+ smooksTreeViewer.setLabelProvider(new
AdapterFactoryLabelProvider(editingDomain.getAdapterFactory()));
smooksTreeViewer.setFilters(new ViewerFilter[] { new TextEObjectModelFilter() });
- List<Resource> resourceList = editingDomain.getResourceSet().getResources();
- if (resourceList.size() == 1) {
- List<EObject> contents = resourceList.get(0).getContents();
- if (contents.size() > 0) {
- smooksTreeViewer.setInput(contents.get(0));
- }
+ Object smooksModel = ((SmooksMultiFormEditor) this.formEditor).getSmooksModel();
+ if (smooksModel != null) {
+ smooksTreeViewer.setInput(smooksModel);
}
createMenuForViewer(smooksTreeViewer);
formEditor.getSite().setSelectionProvider(smooksTreeViewer);
if (formEditor.getEditorSite().getActionBarContributor() instanceof
ISelectionChangedListener) {
smooksTreeViewer.addSelectionChangedListener((ISelectionChangedListener) formEditor
- .getEditorSite().getActionBarContributor());
+ .getEditorSite().getActionBarContributor());
}
gd = new GridData(GridData.FILL_BOTH);
@@ -185,7 +179,7 @@
Menu menu = contextMenu.createContextMenu(smooksTreeViewer2.getControl());
smooksTreeViewer2.getControl().setMenu(menu);
formEditor.getSite().registerContextMenu(contextMenu,
- new UnwrappingSelectionProvider(smooksTreeViewer2));
+ new UnwrappingSelectionProvider(smooksTreeViewer2));
}
public TreeViewer getSmooksTreeViewer() {
@@ -197,8 +191,7 @@
}
public void menuAboutToShow(IMenuManager menuManager) {
- ((IMenuListener) formEditor.getEditorSite().getActionBarContributor())
- .menuAboutToShow(menuManager);
+ ((IMenuListener)
formEditor.getEditorSite().getActionBarContributor()).menuAboutToShow(menuManager);
}
private class TextEObjectModelFilter extends ViewerFilter {
@@ -211,7 +204,7 @@
if (obj instanceof BasicFeatureMapEntry) {
EStructuralFeature sf = ((BasicFeatureMapEntry) obj).getEStructuralFeature();
if (sf.equals(XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT)
- || sf.equals(XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__CDATA)) {
+ || sf.equals(XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__CDATA)) {
return false;
}
}
@@ -219,4 +212,8 @@
}
}
+ public void setSmooksModel(Object model) {
+ smooksTreeViewer.setInput(model);
+ }
+
}
Modified:
workspace/dart/smooksConfigurationsEditor/org.jboss.tools.smooks.configuration/src/org/jboss/tools/smooks/configuration/editors/SmooksMultiFormEditor.java
===================================================================
---
workspace/dart/smooksConfigurationsEditor/org.jboss.tools.smooks.configuration/src/org/jboss/tools/smooks/configuration/editors/SmooksMultiFormEditor.java 2009-04-03
16:29:01 UTC (rev 14503)
+++
workspace/dart/smooksConfigurationsEditor/org.jboss.tools.smooks.configuration/src/org/jboss/tools/smooks/configuration/editors/SmooksMultiFormEditor.java 2009-04-03
17:13:22 UTC (rev 14504)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.smooks.configuration.editors;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
@@ -18,6 +20,8 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
@@ -27,6 +31,7 @@
import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.command.CommandStackListener;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
@@ -35,6 +40,10 @@
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
@@ -56,7 +65,7 @@
* @author Dart Peng (dpeng(a)redhat.com) Date Apr 1, 2009
*/
public class SmooksMultiFormEditor extends FormEditor implements IEditingDomainProvider
{
-
+
public static final String EDITOR_ID =
"org.jboss.tools.smooks.configuration.editors.MultiPageEditor";
private SmooksConfigurationFormPage configurationPage = null;
@@ -69,6 +78,10 @@
private PropertySheetPage propertySheetPage = null;
+ private EObject smooksModel;
+
+ private boolean handleEMFModelChange;
+
public SmooksMultiFormEditor() {
super();
initEditingDomain();
@@ -78,11 +91,10 @@
commandStack.addCommandStackListener(new CommandStackListener() {
public void commandStackChanged(EventObject event) {
firePropertyChange(IEditorPart.PROP_DIRTY);
-
+ handleEMFModelChange();
// Try to select the affected objects.
//
- Command mostRecentCommand = ((CommandStack) event.getSource())
- .getMostRecentCommand();
+ Command mostRecentCommand = ((CommandStack)
event.getSource()).getMostRecentCommand();
if (mostRecentCommand != null) {
setSelectionToViewer(mostRecentCommand.getAffectedObjects());
}
@@ -93,15 +105,55 @@
});
}
+ protected void handleEMFModelChange() {
+ IDocument document =
textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ smooksModel.eResource().save(out, null);
+
+ String newContent = out.toString();
+ String oldContent = document.get();
+
+ int startIndex = 0;
+ while (startIndex < newContent.length() && startIndex <
oldContent.length()
+ && newContent.charAt(startIndex) == oldContent.charAt(startIndex)) {
+ ++startIndex;
+ }
+ int newEndIndex = newContent.length() - 1;
+ int oldEndIndex = oldContent.length() - 1;
+ while (newEndIndex >= startIndex && oldEndIndex >= startIndex
+ && newContent.charAt(newEndIndex) == oldContent.charAt(oldEndIndex)) {
+ --newEndIndex;
+ --oldEndIndex;
+ }
+
+ String replacement = newContent.substring(startIndex, newEndIndex + 1);
+ int length = oldEndIndex - startIndex + 1;
+ handleEMFModelChange = true;
+ document.replace(startIndex, length, replacement);
+ } catch (Exception exception) {
+ SmooksConfigurationActivator.getDefault().log(exception);
+ }
+
+ }
+
@Override
public boolean isDirty() {
- return ((BasicCommandStack) editingDomain.getCommandStack()).isSaveNeeded()
- || super.isDirty();
+ return ((BasicCommandStack) editingDomain.getCommandStack()).isSaveNeeded() ||
super.isDirty();
}
+
+ public EObject getSmooksModel() {
+ return smooksModel;
+ }
+
+ public void setSmooksModel(EObject smooksModel) {
+ this.smooksModel = smooksModel;
+ }
+
private void initEditingDomain() {
- adapterFactory = new ComposedAdapterFactory(
- ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+ adapterFactory = new
ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
adapterFactory.addAdapterFactory(new XslItemProviderAdapterFactory());
@@ -111,7 +163,7 @@
BasicCommandStack commandStack = new BasicCommandStack();
handleCommandStack(commandStack);
editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack,
- new HashMap<Resource, Boolean>());
+ new HashMap<Resource, Boolean>());
}
public void setSelectionToViewer(Collection<?> collection) {
@@ -146,15 +198,78 @@
}
protected StructuredTextEditor createTextEditor() {
- return new SmooksXMLEditor();
+ SmooksXMLEditor xmlEditor = new SmooksXMLEditor(){
+
+ public void createPartControl(Composite parent) {
+ super.createPartControl(parent);
+ getTextViewer().getDocument().addDocumentListener(new 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;
+// handleDocumentChange();
+ } 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.getDefault().log(exception);
+ }
+ }
+ });
+
+ }
+
+ };
+ return xmlEditor;
}
+ protected void handleDocumentChange() {
+ IDocument document =
textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+ String conents = document.get();
+ Resource resource = editingDomain.getResourceSet().getResources().get(0);
+ resource.unload();
+ try {
+ resource.load(new ByteArrayInputStream(conents.getBytes()), Collections.emptyMap());
+ this.smooksModel = resource.getContents().get(0);
+ configurationPage.setSmooksModel(this.smooksModel);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
protected SmooksConfigurationFormPage createSmooksConfigurationFormPage() {
return new SmooksConfigurationFormPage(this, "ConfigurationPage",
"Configuration Page");
}
-
- protected void initSaveOptions(Map<?,?> options){
-
+
+ protected void initSaveOptions(Map<?, ?> options) {
+
}
/*
@@ -179,7 +294,7 @@
}
} catch (IOException e) {
SmooksConfigurationActivator.getDefault().log(e);
- }finally{
+ } finally {
monitor.done();
}
((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
@@ -191,9 +306,10 @@
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));
+ .createPlatformResourceURI(file.getFullPath().toPortableString(), false));
try {
smooksResource.load(Collections.emptyMap());
+ smooksModel = smooksResource.getContents().get(0);
} catch (IOException e) {
throw new PartInitException(e.getMessage());
}