Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 1986 invoked from network); 18 May 2010 15:14:38 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 18 May 2010 15:14:38 -0000 Received: (qmail 38663 invoked by uid 500); 18 May 2010 15:14:37 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 38587 invoked by uid 500); 18 May 2010 15:14:37 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 38580 invoked by uid 99); 18 May 2010 15:14:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 May 2010 15:14:37 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED,AWL X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 May 2010 15:14:32 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 1B6862388C56; Tue, 18 May 2010 15:13:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r945691 [21/39] - in /commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src: main/java/org.apache.commons.scxml.diagram/ main/java/org.apache.commons.scxml.diagram/META-INF/ main/java/org.apache.commons.scxml.diagram/icons/obj16/ main/java/org.... Date: Tue, 18 May 2010 15:13:31 -0000 To: commits@commons.apache.org From: guixl@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100518151407.1B6862388C56@eris.apache.org> Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingDiagramUpdater.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingDocumentProvider.java URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingDocumentProvider.java?rev=945691&view=auto ============================================================================== --- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingDocumentProvider.java (added) +++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingDocumentProvider.java Tue May 18 15:13:13 2010 @@ -0,0 +1,1124 @@ +package org.apache.commons.scxml.modeling.diagram.part; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceStatus; +import org.eclipse.core.resources.IStorage; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.core.runtime.jobs.MultiRule; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.common.ui.URIEditorInput; +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.ecore.util.EContentAdapter; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.transaction.NotificationFilter; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.emf.workspace.util.WorkspaceSynchronizer; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.gmf.runtime.diagram.core.DiagramEditingDomainFactory; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.AbstractDocumentProvider; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.DiagramDocument; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocumentProvider; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocument; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.internal.EditorStatusCodes; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.internal.util.DiagramIOUtil; +import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; +import org.eclipse.gmf.runtime.emf.core.resources.GMFResourceFactory; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.jface.operation.IRunnableContext; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.part.FileEditorInput; + +/** + * @generated + */ +public class ModelingDocumentProvider extends AbstractDocumentProvider + implements IDiagramDocumentProvider { + + /** + * @generated + */ + protected ElementInfo createElementInfo(Object element) + throws CoreException { + if (false == element instanceof FileEditorInput + && false == element instanceof URIEditorInput) { + throw new CoreException( + new Status( + IStatus.ERROR, + ModelingDiagramEditorPlugin.ID, + 0, + NLS + .bind( + Messages.ModelingDocumentProvider_IncorrectInputError, + new Object[] { + element, + "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$ + null)); + } + IEditorInput editorInput = (IEditorInput) element; + IDiagramDocument document = (IDiagramDocument) createDocument(editorInput); + + ResourceSetInfo info = new ResourceSetInfo(document, editorInput); + info.setModificationStamp(computeModificationStamp(info)); + info.fStatus = null; + return info; + } + + /** + * @generated + */ + protected IDocument createDocument(Object element) throws CoreException { + if (false == element instanceof FileEditorInput + && false == element instanceof URIEditorInput) { + throw new CoreException( + new Status( + IStatus.ERROR, + ModelingDiagramEditorPlugin.ID, + 0, + NLS + .bind( + Messages.ModelingDocumentProvider_IncorrectInputError, + new Object[] { + element, + "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$ + null)); + } + IDocument document = createEmptyDocument(); + setDocumentContent(document, (IEditorInput) element); + setupDocument(element, document); + return document; + } + + /** + * Sets up the given document as it would be provided for the given element. The + * content of the document is not changed. This default implementation is empty. + * Subclasses may reimplement. + * + * @param element the blue-print element + * @param document the document to set up + * @generated + */ + protected void setupDocument(Object element, IDocument document) { + // for subclasses + } + + /** + * @generated + */ + private long computeModificationStamp(ResourceSetInfo info) { + int result = 0; + for (Iterator/**/it = info + .getLoadedResourcesIterator(); it.hasNext();) { + Resource nextResource = (Resource) it.next(); + IFile file = WorkspaceSynchronizer.getFile(nextResource); + if (file != null) { + if (file.getLocation() != null) { + result += file.getLocation().toFile().lastModified(); + } else { + result += file.getModificationStamp(); + } + } + } + return result; + } + + /** + * @generated + */ + protected IDocument createEmptyDocument() { + DiagramDocument document = new DiagramDocument(); + document.setEditingDomain(createEditingDomain()); + return document; + } + + /** + * @generated + */ + private TransactionalEditingDomain createEditingDomain() { + TransactionalEditingDomain editingDomain = DiagramEditingDomainFactory + .getInstance().createEditingDomain(); + editingDomain + .setID("org.apache.commons.scxml.modeling.diagram.EditingDomain"); //$NON-NLS-1$ + final NotificationFilter diagramResourceModifiedFilter = NotificationFilter + .createNotifierFilter(editingDomain.getResourceSet()).and( + NotificationFilter + .createEventTypeFilter(Notification.ADD)).and( + NotificationFilter.createFeatureFilter( + ResourceSet.class, + ResourceSet.RESOURCE_SET__RESOURCES)); + editingDomain.getResourceSet().eAdapters().add(new Adapter() { + + private Notifier myTarger; + + public Notifier getTarget() { + return myTarger; + } + + public boolean isAdapterForType(Object type) { + return false; + } + + public void notifyChanged(Notification notification) { + if (diagramResourceModifiedFilter.matches(notification)) { + Object value = notification.getNewValue(); + if (value instanceof Resource) { + ((Resource) value).setTrackingModification(true); + } + } + } + + public void setTarget(Notifier newTarget) { + myTarger = newTarget; + } + + }); + + return editingDomain; + } + + /** + * @generated + */ + protected void setDocumentContent(IDocument document, IEditorInput element) + throws CoreException { + IDiagramDocument diagramDocument = (IDiagramDocument) document; + TransactionalEditingDomain domain = diagramDocument.getEditingDomain(); + if (element instanceof FileEditorInput) { + IStorage storage = ((FileEditorInput) element).getStorage(); + Diagram diagram = DiagramIOUtil.load(domain, storage, true, + getProgressMonitor()); + document.setContent(diagram); + } else if (element instanceof URIEditorInput) { + URI uri = ((URIEditorInput) element).getURI(); + Resource resource = null; + try { + resource = domain.getResourceSet().getResource( + uri.trimFragment(), false); + if (resource == null) { + resource = domain.getResourceSet().createResource( + uri.trimFragment()); + } + if (!resource.isLoaded()) { + try { + Map options = new HashMap(GMFResourceFactory + .getDefaultLoadOptions()); + // @see 171060 + // options.put(org.eclipse.emf.ecore.xmi.XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE); + resource.load(options); + } catch (IOException e) { + resource.unload(); + throw e; + } + } + if (uri.fragment() != null) { + EObject rootElement = resource.getEObject(uri.fragment()); + if (rootElement instanceof Diagram) { + document.setContent((Diagram) rootElement); + return; + } + } else { + for (Iterator it = resource.getContents().iterator(); it + .hasNext();) { + Object rootElement = it.next(); + if (rootElement instanceof Diagram) { + document.setContent((Diagram) rootElement); + return; + } + } + } + throw new RuntimeException( + Messages.ModelingDocumentProvider_NoDiagramInResourceError); + } catch (Exception e) { + CoreException thrownExcp = null; + if (e instanceof CoreException) { + thrownExcp = (CoreException) e; + } else { + String msg = e.getLocalizedMessage(); + thrownExcp = new CoreException( + new Status( + IStatus.ERROR, + ModelingDiagramEditorPlugin.ID, + 0, + msg != null ? msg + : Messages.ModelingDocumentProvider_DiagramLoadingError, + e)); + } + throw thrownExcp; + } + } else { + throw new CoreException( + new Status( + IStatus.ERROR, + ModelingDiagramEditorPlugin.ID, + 0, + NLS + .bind( + Messages.ModelingDocumentProvider_IncorrectInputError, + new Object[] { + element, + "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$ + null)); + } + } + + /** + * @generated + */ + public long getModificationStamp(Object element) { + ResourceSetInfo info = getResourceSetInfo(element); + if (info != null) { + return computeModificationStamp(info); + } + return super.getModificationStamp(element); + } + + /** + * @generated + */ + public boolean isDeleted(Object element) { + IDiagramDocument document = getDiagramDocument(element); + if (document != null) { + Resource diagramResource = document.getDiagram().eResource(); + if (diagramResource != null) { + IFile file = WorkspaceSynchronizer.getFile(diagramResource); + return file == null || file.getLocation() == null + || !file.getLocation().toFile().exists(); + } + } + return super.isDeleted(element); + } + + /** + * @generated + */ + public ResourceSetInfo getResourceSetInfo(Object editorInput) { + return (ResourceSetInfo) super.getElementInfo(editorInput); + } + + /** + * @generated + */ + protected void disposeElementInfo(Object element, ElementInfo info) { + if (info instanceof ResourceSetInfo) { + ResourceSetInfo resourceSetInfo = (ResourceSetInfo) info; + resourceSetInfo.dispose(); + } + super.disposeElementInfo(element, info); + } + + /** + * @generated + */ + protected void doValidateState(Object element, Object computationContext) + throws CoreException { + ResourceSetInfo info = getResourceSetInfo(element); + if (info != null) { + Collection/**/files2Validate = new ArrayList/**/(); + for (Iterator/**/it = info + .getLoadedResourcesIterator(); it.hasNext();) { + Resource nextResource = (Resource) it.next(); + IFile file = WorkspaceSynchronizer.getFile(nextResource); + if (file != null && file.isReadOnly()) { + files2Validate.add(file); + } + } + ResourcesPlugin.getWorkspace().validateEdit( + (IFile[]) files2Validate.toArray(new IFile[files2Validate + .size()]), computationContext); + } + + super.doValidateState(element, computationContext); + } + + /** + * @generated + */ + public boolean isReadOnly(Object element) { + ResourceSetInfo info = getResourceSetInfo(element); + if (info != null) { + if (info.isUpdateCache()) { + try { + updateCache(element); + } catch (CoreException ex) { + ModelingDiagramEditorPlugin.getInstance().logError( + Messages.ModelingDocumentProvider_isModifiable, ex); + // Error message to log was initially taken from org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.StorageDocumentProvider_isModifiable + } + } + return info.isReadOnly(); + } + return super.isReadOnly(element); + } + + /** + * @generated + */ + public boolean isModifiable(Object element) { + if (!isStateValidated(element)) { + if (element instanceof FileEditorInput + || element instanceof URIEditorInput) { + return true; + } + } + ResourceSetInfo info = getResourceSetInfo(element); + if (info != null) { + if (info.isUpdateCache()) { + try { + updateCache(element); + } catch (CoreException ex) { + ModelingDiagramEditorPlugin.getInstance().logError( + Messages.ModelingDocumentProvider_isModifiable, ex); + // Error message to log was initially taken from org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.StorageDocumentProvider_isModifiable + } + } + return info.isModifiable(); + } + return super.isModifiable(element); + } + + /** + * @generated + */ + protected void updateCache(Object element) throws CoreException { + ResourceSetInfo info = getResourceSetInfo(element); + if (info != null) { + for (Iterator/**/it = info + .getLoadedResourcesIterator(); it.hasNext();) { + Resource nextResource = (Resource) it.next(); + IFile file = WorkspaceSynchronizer.getFile(nextResource); + if (file != null && file.isReadOnly()) { + info.setReadOnly(true); + info.setModifiable(false); + return; + } + } + info.setReadOnly(false); + info.setModifiable(true); + return; + } + } + + /** + * @generated + */ + protected void doUpdateStateCache(Object element) throws CoreException { + ResourceSetInfo info = getResourceSetInfo(element); + if (info != null) { + info.setUpdateCache(true); + } + super.doUpdateStateCache(element); + } + + /** + * @generated + */ + public boolean isSynchronized(Object element) { + ResourceSetInfo info = getResourceSetInfo(element); + if (info != null) { + return info.isSynchronized(); + } + return super.isSynchronized(element); + } + + /** + * @generated + */ + protected ISchedulingRule getResetRule(Object element) { + ResourceSetInfo info = getResourceSetInfo(element); + if (info != null) { + Collection/**/rules = new ArrayList/**/(); + for (Iterator/**/it = info + .getLoadedResourcesIterator(); it.hasNext();) { + Resource nextResource = (Resource) it.next(); + IFile file = WorkspaceSynchronizer.getFile(nextResource); + if (file != null) { + rules.add(ResourcesPlugin.getWorkspace().getRuleFactory() + .modifyRule(file)); + } + } + return new MultiRule((ISchedulingRule[]) rules + .toArray(new ISchedulingRule[rules.size()])); + } + return null; + } + + /** + * @generated + */ + protected ISchedulingRule getSaveRule(Object element) { + ResourceSetInfo info = getResourceSetInfo(element); + if (info != null) { + Collection/**/rules = new ArrayList/**/(); + for (Iterator/**/it = info + .getLoadedResourcesIterator(); it.hasNext();) { + Resource nextResource = (Resource) it.next(); + IFile file = WorkspaceSynchronizer.getFile(nextResource); + if (file != null) { + rules.add(computeSchedulingRule(file)); + } + } + return new MultiRule((ISchedulingRule[]) rules + .toArray(new ISchedulingRule[rules.size()])); + } + return null; + } + + /** + * @generated + */ + protected ISchedulingRule getSynchronizeRule(Object element) { + ResourceSetInfo info = getResourceSetInfo(element); + if (info != null) { + Collection/**/rules = new ArrayList/**/(); + for (Iterator/**/it = info + .getLoadedResourcesIterator(); it.hasNext();) { + Resource nextResource = (Resource) it.next(); + IFile file = WorkspaceSynchronizer.getFile(nextResource); + if (file != null) { + rules.add(ResourcesPlugin.getWorkspace().getRuleFactory() + .refreshRule(file)); + } + } + return new MultiRule((ISchedulingRule[]) rules + .toArray(new ISchedulingRule[rules.size()])); + } + return null; + } + + /** + * @generated + */ + protected ISchedulingRule getValidateStateRule(Object element) { + ResourceSetInfo info = getResourceSetInfo(element); + if (info != null) { + Collection/**/files = new ArrayList/**/(); + for (Iterator/**/it = info + .getLoadedResourcesIterator(); it.hasNext();) { + Resource nextResource = (Resource) it.next(); + IFile file = WorkspaceSynchronizer.getFile(nextResource); + if (file != null) { + files.add(file); + } + } + return ResourcesPlugin.getWorkspace().getRuleFactory() + .validateEditRule( + (IFile[]) files.toArray(new IFile[files.size()])); + } + return null; + } + + /** + * @generated + */ + private ISchedulingRule computeSchedulingRule(IResource toCreateOrModify) { + if (toCreateOrModify.exists()) + return ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule( + toCreateOrModify); + + IResource parent = toCreateOrModify; + do { + /* + * XXX This is a workaround for + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=67601 + * IResourceRuleFactory.createRule should iterate the hierarchy + * itself. + */ + toCreateOrModify = parent; + parent = toCreateOrModify.getParent(); + } while (parent != null && !parent.exists()); + + return ResourcesPlugin.getWorkspace().getRuleFactory().createRule( + toCreateOrModify); + } + + /** + * @generated + */ + protected void doSynchronize(Object element, IProgressMonitor monitor) + throws CoreException { + ResourceSetInfo info = getResourceSetInfo(element); + if (info != null) { + for (Iterator/**/it = info + .getLoadedResourcesIterator(); it.hasNext();) { + Resource nextResource = (Resource) it.next(); + handleElementChanged(info, nextResource, monitor); + } + return; + } + super.doSynchronize(element, monitor); + } + + /** + * @generated + */ + protected void doSaveDocument(IProgressMonitor monitor, Object element, + IDocument document, boolean overwrite) throws CoreException { + ResourceSetInfo info = getResourceSetInfo(element); + if (info != null) { + if (!overwrite && !info.isSynchronized()) { + throw new CoreException( + new Status( + IStatus.ERROR, + ModelingDiagramEditorPlugin.ID, + IResourceStatus.OUT_OF_SYNC_LOCAL, + Messages.ModelingDocumentProvider_UnsynchronizedFileSaveError, + null)); + } + info.stopResourceListening(); + fireElementStateChanging(element); + try { + monitor.beginTask( + Messages.ModelingDocumentProvider_SaveDiagramTask, info + .getResourceSet().getResources().size() + 1); //"Saving diagram" + for (Iterator/**/it = info + .getLoadedResourcesIterator(); it.hasNext();) { + Resource nextResource = (Resource) it.next(); + monitor + .setTaskName(NLS + .bind( + Messages.ModelingDocumentProvider_SaveNextResourceTask, + nextResource.getURI())); + if (nextResource.isLoaded() + && !info.getEditingDomain() + .isReadOnly(nextResource)) { + try { + nextResource.save(ModelingDiagramEditorUtil + .getSaveOptions()); + } catch (IOException e) { + fireElementStateChangeFailed(element); + throw new CoreException(new Status(IStatus.ERROR, + ModelingDiagramEditorPlugin.ID, + EditorStatusCodes.RESOURCE_FAILURE, e + .getLocalizedMessage(), null)); + } + } + monitor.worked(1); + } + monitor.done(); + info.setModificationStamp(computeModificationStamp(info)); + } catch (RuntimeException x) { + fireElementStateChangeFailed(element); + throw x; + } finally { + info.startResourceListening(); + } + } else { + URI newResoruceURI; + List affectedFiles = null; + if (element instanceof FileEditorInput) { + IFile newFile = ((FileEditorInput) element).getFile(); + affectedFiles = Collections.singletonList(newFile); + newResoruceURI = URI.createPlatformResourceURI(newFile + .getFullPath().toString(), true); + } else if (element instanceof URIEditorInput) { + newResoruceURI = ((URIEditorInput) element).getURI(); + } else { + fireElementStateChangeFailed(element); + throw new CoreException( + new Status( + IStatus.ERROR, + ModelingDiagramEditorPlugin.ID, + 0, + NLS + .bind( + Messages.ModelingDocumentProvider_IncorrectInputError, + new Object[] { + element, + "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$ + null)); + } + if (false == document instanceof IDiagramDocument) { + fireElementStateChangeFailed(element); + throw new CoreException( + new Status( + IStatus.ERROR, + ModelingDiagramEditorPlugin.ID, + 0, + "Incorrect document used: " + document + " instead of org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument", null)); //$NON-NLS-1$ //$NON-NLS-2$ + } + IDiagramDocument diagramDocument = (IDiagramDocument) document; + final Resource newResource = diagramDocument.getEditingDomain() + .getResourceSet().createResource(newResoruceURI); + final Diagram diagramCopy = (Diagram) EcoreUtil + .copy(diagramDocument.getDiagram()); + try { + new AbstractTransactionalCommand(diagramDocument + .getEditingDomain(), NLS.bind( + Messages.ModelingDocumentProvider_SaveAsOperation, + diagramCopy.getName()), affectedFiles) { + protected CommandResult doExecuteWithResult( + IProgressMonitor monitor, IAdaptable info) + throws ExecutionException { + newResource.getContents().add(diagramCopy); + return CommandResult.newOKCommandResult(); + } + }.execute(monitor, null); + newResource.save(ModelingDiagramEditorUtil.getSaveOptions()); + } catch (ExecutionException e) { + fireElementStateChangeFailed(element); + throw new CoreException(new Status(IStatus.ERROR, + ModelingDiagramEditorPlugin.ID, 0, e + .getLocalizedMessage(), null)); + } catch (IOException e) { + fireElementStateChangeFailed(element); + throw new CoreException(new Status(IStatus.ERROR, + ModelingDiagramEditorPlugin.ID, 0, e + .getLocalizedMessage(), null)); + } + newResource.unload(); + } + } + + /** + * @generated + */ + protected void handleElementChanged(ResourceSetInfo info, + Resource changedResource, IProgressMonitor monitor) { + IFile file = WorkspaceSynchronizer.getFile(changedResource); + if (file != null) { + try { + file.refreshLocal(IResource.DEPTH_INFINITE, monitor); + } catch (CoreException ex) { + ModelingDiagramEditorPlugin + .getInstance() + .logError( + Messages.ModelingDocumentProvider_handleElementContentChanged, + ex); + // Error message to log was initially taken from org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.FileDocumentProvider_handleElementContentChanged + } + } + changedResource.unload(); + + fireElementContentAboutToBeReplaced(info.getEditorInput()); + removeUnchangedElementListeners(info.getEditorInput(), info); + info.fStatus = null; + try { + setDocumentContent(info.fDocument, info.getEditorInput()); + } catch (CoreException e) { + info.fStatus = e.getStatus(); + } + if (!info.fCanBeSaved) { + info.setModificationStamp(computeModificationStamp(info)); + } + addUnchangedElementListeners(info.getEditorInput(), info); + fireElementContentReplaced(info.getEditorInput()); + } + + /** + * @generated + */ + protected void handleElementMoved(IEditorInput input, URI uri) { + if (input instanceof FileEditorInput) { + IFile newFile = ResourcesPlugin.getWorkspace().getRoot().getFile( + new Path(URI.decode(uri.path())).removeFirstSegments(1)); + fireElementMoved(input, newFile == null ? null + : new FileEditorInput(newFile)); + return; + } + // TODO: append suffix to the URI! (use diagram as a parameter) + fireElementMoved(input, new URIEditorInput(uri)); + } + + /** + * @generated + */ + public IEditorInput createInputWithEditingDomain(IEditorInput editorInput, + TransactionalEditingDomain domain) { + return editorInput; + } + + /** + * @generated + */ + public IDiagramDocument getDiagramDocument(Object element) { + IDocument doc = getDocument(element); + if (doc instanceof IDiagramDocument) { + return (IDiagramDocument) doc; + } + return null; + } + + /** + * @generated + */ + protected IRunnableContext getOperationRunner(IProgressMonitor monitor) { + return null; + } + + /** + * @generated + */ + protected class ResourceSetInfo extends ElementInfo { + + /** + * @generated + */ + private long myModificationStamp = IResource.NULL_STAMP; + + /** + * @generated + */ + private WorkspaceSynchronizer mySynchronizer; + + /** + * @generated + */ + private Collection myUnSynchronizedResources = new ArrayList(); + + /** + * @generated + */ + private IDiagramDocument myDocument; + + /** + * @generated + */ + private IEditorInput myEditorInput; + + /** + * @generated + */ + private boolean myUpdateCache = true; + + /** + * @generated + */ + private boolean myModifiable = false; + + /** + * @generated + */ + private boolean myReadOnly = true; + + /** + * @generated + */ + private ResourceSetModificationListener myResourceSetListener; + + /** + * @generated + */ + public ResourceSetInfo(IDiagramDocument document, + IEditorInput editorInput) { + super(document); + myDocument = document; + myEditorInput = editorInput; + startResourceListening(); + myResourceSetListener = new ResourceSetModificationListener(this); + getResourceSet().eAdapters().add(myResourceSetListener); + } + + /** + * @generated + */ + public long getModificationStamp() { + return myModificationStamp; + } + + /** + * @generated + */ + public void setModificationStamp(long modificationStamp) { + myModificationStamp = modificationStamp; + } + + /** + * @generated + */ + public TransactionalEditingDomain getEditingDomain() { + return myDocument.getEditingDomain(); + } + + /** + * @generated + */ + public ResourceSet getResourceSet() { + return getEditingDomain().getResourceSet(); + } + + /** + * @generated + */ + public Iterator/**/getLoadedResourcesIterator() { + return new ArrayList/**/( + getResourceSet().getResources()).iterator(); + } + + /** + * @generated + */ + public IEditorInput getEditorInput() { + return myEditorInput; + } + + /** + * @generated + */ + public void dispose() { + stopResourceListening(); + getResourceSet().eAdapters().remove(myResourceSetListener); + for (Iterator/**/it = getLoadedResourcesIterator(); it + .hasNext();) { + Resource resource = (Resource) it.next(); + resource.unload(); + } + } + + /** + * @generated + */ + public boolean isSynchronized() { + return myUnSynchronizedResources.size() == 0; + } + + /** + * @generated + */ + public void setUnSynchronized(Resource resource) { + myUnSynchronizedResources.add(resource); + } + + /** + * @generated + */ + public void setSynchronized(Resource resource) { + myUnSynchronizedResources.remove(resource); + } + + /** + * @generated + */ + public final void stopResourceListening() { + mySynchronizer.dispose(); + mySynchronizer = null; + } + + /** + * @generated + */ + public final void startResourceListening() { + mySynchronizer = new WorkspaceSynchronizer(getEditingDomain(), + new SynchronizerDelegate()); + } + + /** + * @generated + */ + public boolean isUpdateCache() { + return myUpdateCache; + } + + /** + * @generated + */ + public void setUpdateCache(boolean update) { + myUpdateCache = update; + } + + /** + * @generated + */ + public boolean isModifiable() { + return myModifiable; + } + + /** + * @generated + */ + public void setModifiable(boolean modifiable) { + myModifiable = modifiable; + } + + /** + * @generated + */ + public boolean isReadOnly() { + return myReadOnly; + } + + /** + * @generated + */ + public void setReadOnly(boolean readOnly) { + myReadOnly = readOnly; + } + + /** + * @generated + */ + private class SynchronizerDelegate implements + WorkspaceSynchronizer.Delegate { + + /** + * @generated + */ + public void dispose() { + } + + /** + * @generated + */ + public boolean handleResourceChanged(final Resource resource) { + synchronized (ResourceSetInfo.this) { + if (ResourceSetInfo.this.fCanBeSaved) { + ResourceSetInfo.this.setUnSynchronized(resource); + return true; + } + } + Display.getDefault().asyncExec(new Runnable() { + public void run() { + handleElementChanged(ResourceSetInfo.this, resource, + null); + } + }); + return true; + } + + /** + * @generated + */ + public boolean handleResourceDeleted(Resource resource) { + synchronized (ResourceSetInfo.this) { + if (ResourceSetInfo.this.fCanBeSaved) { + ResourceSetInfo.this.setUnSynchronized(resource); + return true; + } + } + Display.getDefault().asyncExec(new Runnable() { + public void run() { + fireElementDeleted(ResourceSetInfo.this + .getEditorInput()); + } + }); + return true; + } + + /** + * @generated + */ + public boolean handleResourceMoved(Resource resource, + final URI newURI) { + synchronized (ResourceSetInfo.this) { + if (ResourceSetInfo.this.fCanBeSaved) { + ResourceSetInfo.this.setUnSynchronized(resource); + return true; + } + } + if (myDocument.getDiagram().eResource() == resource) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + handleElementMoved(ResourceSetInfo.this + .getEditorInput(), newURI); + } + }); + } else { + handleResourceDeleted(resource); + } + return true; + } + + } + + } + + /** + * @generated + */ + private class ResourceSetModificationListener extends EContentAdapter { + + /** + * @generated + */ + private NotificationFilter myModifiedFilter; + + /** + * @generated + */ + private ResourceSetInfo myInfo; + + /** + * @generated + */ + public ResourceSetModificationListener(ResourceSetInfo info) { + myInfo = info; + myModifiedFilter = NotificationFilter.createEventTypeFilter( + Notification.SET).or( + NotificationFilter + .createEventTypeFilter(Notification.UNSET)).and( + NotificationFilter.createFeatureFilter(Resource.class, + Resource.RESOURCE__IS_MODIFIED)); + } + + /** + * @generated + */ + public void notifyChanged(Notification notification) { + if (notification.getNotifier() instanceof ResourceSet) { + super.notifyChanged(notification); + } + if (!notification.isTouch() + && myModifiedFilter.matches(notification)) { + if (notification.getNotifier() instanceof Resource) { + Resource resource = (Resource) notification.getNotifier(); + if (resource.isLoaded()) { + boolean modified = false; + for (Iterator/**/it = myInfo + .getLoadedResourcesIterator(); it.hasNext() + && !modified;) { + Resource nextResource = (Resource) it.next(); + if (nextResource.isLoaded()) { + modified = nextResource.isModified(); + } + } + boolean dirtyStateChanged = false; + synchronized (myInfo) { + if (modified != myInfo.fCanBeSaved) { + myInfo.fCanBeSaved = modified; + dirtyStateChanged = true; + } + if (!resource.isModified()) { + myInfo.setSynchronized(resource); + } + } + if (dirtyStateChanged) { + fireElementDirtyStateChanged(myInfo + .getEditorInput(), modified); + + if (!modified) { + myInfo + .setModificationStamp(computeModificationStamp(myInfo)); + } + } + } + } + } + } + + } + +} Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingDocumentProvider.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingDomainModelElementTester.java URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingDomainModelElementTester.java?rev=945691&view=auto ============================================================================== --- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingDomainModelElementTester.java (added) +++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingDomainModelElementTester.java Tue May 18 15:13:13 2010 @@ -0,0 +1,116 @@ +package org.apache.commons.scxml.modeling.diagram.part; + +import org.apache.commons.scxml.modeling.ModelingPackage; +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; + +/** + * @generated + */ +public class ModelingDomainModelElementTester extends PropertyTester { + + /** + * @generated + */ + public boolean test(Object receiver, String method, Object[] args, + Object expectedValue) { + if (false == receiver instanceof EObject) { + return false; + } + EObject eObject = (EObject) receiver; + EClass eClass = eObject.eClass(); + if (eClass == ModelingPackage.eINSTANCE.getNamedElement()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getState()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getTranslation()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getAssign()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getServiceTemplate()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getExecutableContent()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getOnEntry()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getOnExit()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getInitialState()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getFinalState()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getParallel()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getHistoryState()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getRaise()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getIf()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getElseIf()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getElse()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getLog()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getExtenExecContent()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getDataModel()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getData()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getValidate()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getParam()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getScript()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getAnchor()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getSend()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getCancel()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getContent()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getDonedata()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getInvoke()) { + return true; + } + if (eClass == ModelingPackage.eINSTANCE.getFinalize()) { + return true; + } + return false; + } + +} Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingDomainModelElementTester.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingInitDiagramFileAction.java URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingInitDiagramFileAction.java?rev=945691&view=auto ============================================================================== --- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingInitDiagramFileAction.java (added) +++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingInitDiagramFileAction.java Tue May 18 15:13:13 2010 @@ -0,0 +1,101 @@ +package org.apache.commons.scxml.modeling.diagram.part; + +import org.apache.commons.scxml.modeling.diagram.edit.parts.ServiceTemplateEditPart; +import org.eclipse.core.resources.IFile; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.common.util.WrappedException; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IObjectActionDelegate; +import org.eclipse.ui.IWorkbenchPart; + +/** + * @generated + */ +public class ModelingInitDiagramFileAction implements IObjectActionDelegate { + + /** + * @generated + */ + private IWorkbenchPart targetPart; + + /** + * @generated + */ + private URI domainModelURI; + + /** + * @generated + */ + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + this.targetPart = targetPart; + } + + /** + * @generated + */ + public void selectionChanged(IAction action, ISelection selection) { + domainModelURI = null; + action.setEnabled(false); + if (selection instanceof IStructuredSelection == false + || selection.isEmpty()) { + return; + } + IFile file = (IFile) ((IStructuredSelection) selection) + .getFirstElement(); + domainModelURI = URI.createPlatformResourceURI(file.getFullPath() + .toString(), true); + action.setEnabled(true); + } + + /** + * @generated + */ + private Shell getShell() { + return targetPart.getSite().getShell(); + } + + /** + * @generated + */ + public void run(IAction action) { + TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE + .createEditingDomain(); + ResourceSet resourceSet = editingDomain.getResourceSet(); + EObject diagramRoot = null; + try { + Resource resource = resourceSet.getResource(domainModelURI, true); + diagramRoot = (EObject) resource.getContents().get(0); + } catch (WrappedException ex) { + ModelingDiagramEditorPlugin.getInstance().logError( + "Unable to load resource: " + domainModelURI, ex); //$NON-NLS-1$ + } + if (diagramRoot == null) { + MessageDialog + .openError( + getShell(), + Messages.ModelingInitDiagramFileAction_InitDiagramFileResourceErrorDialogTitle, + Messages.ModelingInitDiagramFileAction_InitDiagramFileResourceErrorDialogMessage); + return; + } + Wizard wizard = new ModelingNewDiagramFileWizard(domainModelURI, + diagramRoot, editingDomain); + wizard + .setWindowTitle(NLS + .bind( + Messages.ModelingInitDiagramFileAction_InitDiagramFileWizardTitle, + ServiceTemplateEditPart.MODEL_ID)); + ModelingDiagramEditorUtil.runWizard(getShell(), wizard, + "InitDiagramFile"); //$NON-NLS-1$ + } +} Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingInitDiagramFileAction.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingLinkDescriptor.java URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingLinkDescriptor.java?rev=945691&view=auto ============================================================================== --- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingLinkDescriptor.java (added) +++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingLinkDescriptor.java Tue May 18 15:13:13 2010 @@ -0,0 +1,93 @@ +package org.apache.commons.scxml.modeling.diagram.part; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.emf.type.core.IElementType; + +/** + * @generated + */ +public class ModelingLinkDescriptor extends ModelingNodeDescriptor { + + /** + * @generated + */ + private EObject mySource; + + /** + * @generated + */ + private EObject myDestination; + + /** + * @generated + */ + private IAdaptable mySemanticAdapter; + + /** + * @generated + */ + private ModelingLinkDescriptor(EObject source, EObject destination, + EObject linkElement, int linkVID) { + super(linkElement, linkVID); + mySource = source; + myDestination = destination; + } + + /** + * @generated + */ + public ModelingLinkDescriptor(EObject source, EObject destination, + IElementType elementType, int linkVID) { + this(source, destination, (EObject) null, linkVID); + final IElementType elementTypeCopy = elementType; + mySemanticAdapter = new IAdaptable() { + public Object getAdapter(Class adapter) { + if (IElementType.class.equals(adapter)) { + return elementTypeCopy; + } + return null; + } + }; + } + + /** + * @generated + */ + public ModelingLinkDescriptor(EObject source, EObject destination, + EObject linkElement, IElementType elementType, int linkVID) { + this(source, destination, linkElement, linkVID); + final IElementType elementTypeCopy = elementType; + mySemanticAdapter = new EObjectAdapter(linkElement) { + public Object getAdapter(Class adapter) { + if (IElementType.class.equals(adapter)) { + return elementTypeCopy; + } + return super.getAdapter(adapter); + } + }; + } + + /** + * @generated + */ + public EObject getSource() { + return mySource; + } + + /** + * @generated + */ + public EObject getDestination() { + return myDestination; + } + + /** + * @generated + */ + public IAdaptable getSemanticAdapter() { + return mySemanticAdapter; + } + +} Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingLinkDescriptor.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingLoadResourceAction.java URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingLoadResourceAction.java?rev=945691&view=auto ============================================================================== --- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingLoadResourceAction.java (added) +++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingLoadResourceAction.java Tue May 18 15:13:13 2010 @@ -0,0 +1,66 @@ +package org.apache.commons.scxml.modeling.diagram.part; + +import org.apache.commons.scxml.modeling.diagram.edit.parts.ServiceTemplateEditPart; +import org.eclipse.emf.edit.ui.action.LoadResourceAction; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IObjectActionDelegate; +import org.eclipse.ui.IWorkbenchPart; + +/** + * @generated + */ +public class ModelingLoadResourceAction implements IObjectActionDelegate { + + /** + * @generated + */ + private ServiceTemplateEditPart mySelectedElement; + + /** + * @generated + */ + private Shell myShell; + + /** + * @generated + */ + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + myShell = targetPart.getSite().getShell(); + } + + /** + * @generated + */ + public void run(IAction action) { + LoadResourceAction.LoadResourceDialog loadResourceDialog = new LoadResourceAction.LoadResourceDialog( + myShell, mySelectedElement.getEditingDomain()); + loadResourceDialog.open(); + } + + /** + * @generated + */ + public void selectionChanged(IAction action, ISelection selection) { + mySelectedElement = null; + if (selection instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = (IStructuredSelection) selection; + if (structuredSelection.size() == 1 + && structuredSelection.getFirstElement() instanceof ServiceTemplateEditPart) { + mySelectedElement = (ServiceTemplateEditPart) structuredSelection + .getFirstElement(); + } + } + action.setEnabled(isEnabled()); + } + + /** + * @generated + */ + private boolean isEnabled() { + return mySelectedElement != null; + } + +} Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingLoadResourceAction.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingMatchingStrategy.java URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingMatchingStrategy.java?rev=945691&view=auto ============================================================================== --- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingMatchingStrategy.java (added) +++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingMatchingStrategy.java Tue May 18 15:13:13 2010 @@ -0,0 +1,36 @@ +package org.apache.commons.scxml.modeling.diagram.part; + +import org.eclipse.emf.common.ui.URIEditorInput; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorMatchingStrategy; +import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.PartInitException; + +/** + * @generated + */ +public class ModelingMatchingStrategy implements IEditorMatchingStrategy { + + /** + * @generated + */ + public boolean matches(IEditorReference editorRef, IEditorInput input) { + IEditorInput editorInput; + try { + editorInput = editorRef.getEditorInput(); + } catch (PartInitException e) { + return false; + } + + if (editorInput.equals(input)) { + return true; + } + if (editorInput instanceof URIEditorInput + && input instanceof URIEditorInput) { + return ((URIEditorInput) editorInput).getURI().equals( + ((URIEditorInput) input).getURI()); + } + return false; + } + +} Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingMatchingStrategy.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDiagramFileWizard.java URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDiagramFileWizard.java?rev=945691&view=auto ============================================================================== --- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDiagramFileWizard.java (added) +++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDiagramFileWizard.java Tue May 18 15:13:13 2010 @@ -0,0 +1,199 @@ +package org.apache.commons.scxml.modeling.diagram.part; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.scxml.modeling.diagram.edit.parts.ServiceTemplateEditPart; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.operations.OperationHistoryFactory; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +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.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.gmf.runtime.diagram.core.services.ViewService; +import org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation; +import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.osgi.util.NLS; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.dialogs.WizardNewFileCreationPage; + +/** + * @generated + */ +public class ModelingNewDiagramFileWizard extends Wizard { + + /** + * @generated + */ + private WizardNewFileCreationPage myFileCreationPage; + + /** + * @generated + */ + private ModelElementSelectionPage diagramRootElementSelectionPage; + + /** + * @generated + */ + private TransactionalEditingDomain myEditingDomain; + + /** + * @generated + */ + public ModelingNewDiagramFileWizard(URI domainModelURI, + EObject diagramRoot, TransactionalEditingDomain editingDomain) { + assert domainModelURI != null : "Domain model uri must be specified"; //$NON-NLS-1$ + assert diagramRoot != null : "Doagram root element must be specified"; //$NON-NLS-1$ + assert editingDomain != null : "Editing domain must be specified"; //$NON-NLS-1$ + + myFileCreationPage = new WizardNewFileCreationPage( + Messages.ModelingNewDiagramFileWizard_CreationPageName, + StructuredSelection.EMPTY); + myFileCreationPage + .setTitle(Messages.ModelingNewDiagramFileWizard_CreationPageTitle); + myFileCreationPage.setDescription(NLS.bind( + Messages.ModelingNewDiagramFileWizard_CreationPageDescription, + ServiceTemplateEditPart.MODEL_ID)); + IPath filePath; + String fileName = domainModelURI.trimFileExtension().lastSegment(); + if (domainModelURI.isPlatformResource()) { + filePath = new Path(domainModelURI.trimSegments(1) + .toPlatformString(true)); + } else if (domainModelURI.isFile()) { + filePath = new Path(domainModelURI.trimSegments(1).toFileString()); + } else { + // TODO : use some default path + throw new IllegalArgumentException( + "Unsupported URI: " + domainModelURI); //$NON-NLS-1$ + } + myFileCreationPage.setContainerFullPath(filePath); + myFileCreationPage.setFileName(ModelingDiagramEditorUtil + .getUniqueFileName(filePath, fileName, "modeling_diagram")); //$NON-NLS-1$ + + diagramRootElementSelectionPage = new DiagramRootElementSelectionPage( + Messages.ModelingNewDiagramFileWizard_RootSelectionPageName); + diagramRootElementSelectionPage + .setTitle(Messages.ModelingNewDiagramFileWizard_RootSelectionPageTitle); + diagramRootElementSelectionPage + .setDescription(Messages.ModelingNewDiagramFileWizard_RootSelectionPageDescription); + diagramRootElementSelectionPage.setModelElement(diagramRoot); + + myEditingDomain = editingDomain; + } + + /** + * @generated + */ + public void addPages() { + addPage(myFileCreationPage); + addPage(diagramRootElementSelectionPage); + } + + /** + * @generated + */ + public boolean performFinish() { + List affectedFiles = new LinkedList(); + IFile diagramFile = myFileCreationPage.createNewFile(); + ModelingDiagramEditorUtil.setCharset(diagramFile); + affectedFiles.add(diagramFile); + URI diagramModelURI = URI.createPlatformResourceURI(diagramFile + .getFullPath().toString(), true); + ResourceSet resourceSet = myEditingDomain.getResourceSet(); + final Resource diagramResource = resourceSet + .createResource(diagramModelURI); + AbstractTransactionalCommand command = new AbstractTransactionalCommand( + myEditingDomain, + Messages.ModelingNewDiagramFileWizard_InitDiagramCommand, + affectedFiles) { + + protected CommandResult doExecuteWithResult( + IProgressMonitor monitor, IAdaptable info) + throws ExecutionException { + int diagramVID = ModelingVisualIDRegistry + .getDiagramVisualID(diagramRootElementSelectionPage + .getModelElement()); + if (diagramVID != ServiceTemplateEditPart.VISUAL_ID) { + return CommandResult + .newErrorCommandResult(Messages.ModelingNewDiagramFileWizard_IncorrectRootError); + } + Diagram diagram = ViewService.createDiagram( + diagramRootElementSelectionPage.getModelElement(), + ServiceTemplateEditPart.MODEL_ID, + ModelingDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT); + diagramResource.getContents().add(diagram); + return CommandResult.newOKCommandResult(); + } + }; + try { + OperationHistoryFactory.getOperationHistory().execute(command, + new NullProgressMonitor(), null); + diagramResource.save(ModelingDiagramEditorUtil.getSaveOptions()); + ModelingDiagramEditorUtil.openDiagram(diagramResource); + } catch (ExecutionException e) { + ModelingDiagramEditorPlugin.getInstance().logError( + "Unable to create model and diagram", e); //$NON-NLS-1$ + } catch (IOException ex) { + ModelingDiagramEditorPlugin.getInstance().logError( + "Save operation failed for: " + diagramModelURI, ex); //$NON-NLS-1$ + } catch (PartInitException ex) { + ModelingDiagramEditorPlugin.getInstance().logError( + "Unable to open editor", ex); //$NON-NLS-1$ + } + return true; + } + + /** + * @generated + */ + private static class DiagramRootElementSelectionPage extends + ModelElementSelectionPage { + + /** + * @generated + */ + protected DiagramRootElementSelectionPage(String pageName) { + super(pageName); + } + + /** + * @generated + */ + protected String getSelectionTitle() { + return Messages.ModelingNewDiagramFileWizard_RootSelectionPageSelectionTitle; + } + + /** + * @generated + */ + protected boolean validatePage() { + if (selectedModelElement == null) { + setErrorMessage(Messages.ModelingNewDiagramFileWizard_RootSelectionPageNoSelectionMessage); + return false; + } + boolean result = ViewService + .getInstance() + .provides( + new CreateDiagramViewOperation( + new EObjectAdapter(selectedModelElement), + ServiceTemplateEditPart.MODEL_ID, + ModelingDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT)); + setErrorMessage(result ? null + : Messages.ModelingNewDiagramFileWizard_RootSelectionPageInvalidSelectionMessage); + return result; + } + } +} Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNewDiagramFileWizard.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNodeDescriptor.java URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNodeDescriptor.java?rev=945691&view=auto ============================================================================== --- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNodeDescriptor.java (added) +++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNodeDescriptor.java Tue May 18 15:13:13 2010 @@ -0,0 +1,57 @@ +package org.apache.commons.scxml.modeling.diagram.part; + +import org.eclipse.emf.ecore.EObject; + +/** + * @generated + */ +public class ModelingNodeDescriptor { + + /** + * @generated + */ + private EObject myModelElement; + + /** + * @generated + */ + private int myVisualID; + + /** + * @generated + */ + private String myType; + + /** + * @generated + */ + public ModelingNodeDescriptor(EObject modelElement, int visualID) { + myModelElement = modelElement; + myVisualID = visualID; + } + + /** + * @generated + */ + public EObject getModelElement() { + return myModelElement; + } + + /** + * @generated + */ + public int getVisualID() { + return myVisualID; + } + + /** + * @generated + */ + public String getType() { + if (myType == null) { + myType = ModelingVisualIDRegistry.getType(getVisualID()); + } + return myType; + } + +} Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingNodeDescriptor.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingPaletteFactory.java URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingPaletteFactory.java?rev=945691&view=auto ============================================================================== --- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingPaletteFactory.java (added) +++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingPaletteFactory.java Tue May 18 15:13:13 2010 @@ -0,0 +1,551 @@ +package org.apache.commons.scxml.modeling.diagram.part; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.scxml.modeling.diagram.providers.ModelingElementTypes; +import org.eclipse.gef.Tool; +import org.eclipse.gef.palette.PaletteContainer; +import org.eclipse.gef.palette.PaletteGroup; +import org.eclipse.gef.palette.PaletteRoot; +import org.eclipse.gef.palette.ToolEntry; +import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeConnectionTool; +import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeCreationTool; + +/** + * @generated + */ +public class ModelingPaletteFactory { + + /** + * @generated + */ + public void fillPalette(PaletteRoot paletteRoot) { + paletteRoot.add(createScxml1Group()); + } + + /** + * Creates "scxml" palette tool group + * @generated + */ + private PaletteContainer createScxml1Group() { + PaletteGroup paletteContainer = new PaletteGroup( + Messages.Scxml1Group_title); + paletteContainer.add(createState1CreationTool()); + paletteContainer.add(createTranslation2CreationTool()); + paletteContainer.add(createAssign3CreationTool()); + paletteContainer.add(createOnEntry4CreationTool()); + paletteContainer.add(createOnExit5CreationTool()); + paletteContainer.add(createInitialState6CreationTool()); + paletteContainer.add(createFinalState7CreationTool()); + paletteContainer.add(createParallel8CreationTool()); + paletteContainer.add(createHistoryState9CreationTool()); + paletteContainer.add(createRaise10CreationTool()); + paletteContainer.add(createIf11CreationTool()); + paletteContainer.add(createElseIf12CreationTool()); + paletteContainer.add(createElse13CreationTool()); + paletteContainer.add(createLog14CreationTool()); + paletteContainer.add(createExtenExecContent15CreationTool()); + paletteContainer.add(createDataModel16CreationTool()); + paletteContainer.add(createData17CreationTool()); + paletteContainer.add(createValidate18CreationTool()); + paletteContainer.add(createParam19CreationTool()); + paletteContainer.add(createScript20CreationTool()); + paletteContainer.add(createAnchor21CreationTool()); + paletteContainer.add(createSend22CreationTool()); + paletteContainer.add(createCancel23CreationTool()); + paletteContainer.add(createContent24CreationTool()); + paletteContainer.add(createDonedata25CreationTool()); + paletteContainer.add(createInvoke26CreationTool()); + paletteContainer.add(createFinalize27CreationTool()); + return paletteContainer; + } + + /** + * @generated + */ + private ToolEntry createState1CreationTool() { + List/**/types = new ArrayList/**/(3); + types.add(ModelingElementTypes.State_1001); + types.add(ModelingElementTypes.State_2038); + types.add(ModelingElementTypes.State_2046); + NodeToolEntry entry = new NodeToolEntry( + Messages.State1CreationTool_title, + Messages.State1CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.State_1001)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createTranslation2CreationTool() { + List/**/types = new ArrayList/**/(1); + types.add(ModelingElementTypes.Translation_3001); + LinkToolEntry entry = new LinkToolEntry( + Messages.Translation2CreationTool_title, + Messages.Translation2CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Translation_3001)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createAssign3CreationTool() { + List/**/types = new ArrayList/**/(2); + types.add(ModelingElementTypes.Assign_2005); + types.add(ModelingElementTypes.Assign_2018); + NodeToolEntry entry = new NodeToolEntry( + Messages.Assign3CreationTool_title, + Messages.Assign3CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Assign_2005)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createOnEntry4CreationTool() { + List/**/types = new ArrayList/**/(3); + types.add(ModelingElementTypes.OnEntry_2001); + types.add(ModelingElementTypes.OnEntry_2036); + types.add(ModelingElementTypes.OnEntry_2044); + NodeToolEntry entry = new NodeToolEntry( + Messages.OnEntry4CreationTool_title, + Messages.OnEntry4CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.OnEntry_2001)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createOnExit5CreationTool() { + List/**/types = new ArrayList/**/(3); + types.add(ModelingElementTypes.OnExit_2016); + types.add(ModelingElementTypes.OnExit_2037); + types.add(ModelingElementTypes.OnExit_2045); + NodeToolEntry entry = new NodeToolEntry( + Messages.OnExit5CreationTool_title, + Messages.OnExit5CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.OnExit_2016)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createInitialState6CreationTool() { + List/**/types = new ArrayList/**/(2); + types.add(ModelingElementTypes.InitialState_2030); + types.add(ModelingElementTypes.InitialState_1002); + NodeToolEntry entry = new NodeToolEntry( + Messages.InitialState6CreationTool_title, + Messages.InitialState6CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.InitialState_2030)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createFinalState7CreationTool() { + List/**/types = new ArrayList/**/(2); + types.add(ModelingElementTypes.FinalState_2040); + types.add(ModelingElementTypes.FinalState_1006); + NodeToolEntry entry = new NodeToolEntry( + Messages.FinalState7CreationTool_title, + Messages.FinalState7CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.FinalState_2040)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createParallel8CreationTool() { + List/**/types = new ArrayList/**/(3); + types.add(ModelingElementTypes.Parallel_2032); + types.add(ModelingElementTypes.Parallel_2035); + types.add(ModelingElementTypes.Parallel_1004); + NodeToolEntry entry = new NodeToolEntry( + Messages.Parallel8CreationTool_title, + Messages.Parallel8CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Parallel_2032)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createHistoryState9CreationTool() { + List/**/types = new ArrayList/**/(2); + types.add(ModelingElementTypes.HistoryState_2031); + types.add(ModelingElementTypes.HistoryState_2033); + NodeToolEntry entry = new NodeToolEntry( + Messages.HistoryState9CreationTool_title, + Messages.HistoryState9CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.HistoryState_2031)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createRaise10CreationTool() { + List/**/types = new ArrayList/**/(2); + types.add(ModelingElementTypes.Raise_2006); + types.add(ModelingElementTypes.Raise_2019); + NodeToolEntry entry = new NodeToolEntry( + Messages.Raise10CreationTool_title, + Messages.Raise10CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Raise_2006)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createIf11CreationTool() { + List/**/types = new ArrayList/**/(2); + types.add(ModelingElementTypes.If_2002); + types.add(ModelingElementTypes.If_2017); + NodeToolEntry entry = new NodeToolEntry( + Messages.If11CreationTool_title, + Messages.If11CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.If_2002)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createElseIf12CreationTool() { + List/**/types = new ArrayList/**/(1); + types.add(ModelingElementTypes.ElseIf_2003); + NodeToolEntry entry = new NodeToolEntry( + Messages.ElseIf12CreationTool_title, + Messages.ElseIf12CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.ElseIf_2003)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createElse13CreationTool() { + List/**/types = new ArrayList/**/(1); + types.add(ModelingElementTypes.Else_2004); + NodeToolEntry entry = new NodeToolEntry( + Messages.Else13CreationTool_title, + Messages.Else13CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Else_2004)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createLog14CreationTool() { + List/**/types = new ArrayList/**/(2); + types.add(ModelingElementTypes.Log_2007); + types.add(ModelingElementTypes.Log_2020); + NodeToolEntry entry = new NodeToolEntry( + Messages.Log14CreationTool_title, + Messages.Log14CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Log_2007)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createExtenExecContent15CreationTool() { + ToolEntry entry = new ToolEntry( + Messages.ExtenExecContent15CreationTool_title, + Messages.ExtenExecContent15CreationTool_desc, null, null) { + }; + return entry; + } + + /** + * @generated + */ + private ToolEntry createDataModel16CreationTool() { + List/**/types = new ArrayList/**/(1); + types.add(ModelingElementTypes.DataModel_1005); + NodeToolEntry entry = new NodeToolEntry( + Messages.DataModel16CreationTool_title, + Messages.DataModel16CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.DataModel_1005)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createData17CreationTool() { + List/**/types = new ArrayList/**/(1); + types.add(ModelingElementTypes.Data_2047); + NodeToolEntry entry = new NodeToolEntry( + Messages.Data17CreationTool_title, + Messages.Data17CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Data_2047)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createValidate18CreationTool() { + List/**/types = new ArrayList/**/(2); + types.add(ModelingElementTypes.Validate_2008); + types.add(ModelingElementTypes.Validate_2021); + NodeToolEntry entry = new NodeToolEntry( + Messages.Validate18CreationTool_title, + Messages.Validate18CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Validate_2008)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createParam19CreationTool() { + List/**/types = new ArrayList/**/(5); + types.add(ModelingElementTypes.Param_2011); + types.add(ModelingElementTypes.Param_2014); + types.add(ModelingElementTypes.Param_2023); + types.add(ModelingElementTypes.Param_2028); + types.add(ModelingElementTypes.Param_2042); + NodeToolEntry entry = new NodeToolEntry( + Messages.Param19CreationTool_title, + Messages.Param19CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Param_2011)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createScript20CreationTool() { + List/**/types = new ArrayList/**/(3); + types.add(ModelingElementTypes.Script_2015); + types.add(ModelingElementTypes.Script_2025); + types.add(ModelingElementTypes.Script_1003); + NodeToolEntry entry = new NodeToolEntry( + Messages.Script20CreationTool_title, + Messages.Script20CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Script_2015)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createAnchor21CreationTool() { + List/**/types = new ArrayList/**/(2); + types.add(ModelingElementTypes.Anchor_2034); + types.add(ModelingElementTypes.Anchor_2039); + NodeToolEntry entry = new NodeToolEntry( + Messages.Anchor21CreationTool_title, + Messages.Anchor21CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Anchor_2034)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createSend22CreationTool() { + List/**/types = new ArrayList/**/(2); + types.add(ModelingElementTypes.Send_2010); + types.add(ModelingElementTypes.Send_2024); + NodeToolEntry entry = new NodeToolEntry( + Messages.Send22CreationTool_title, + Messages.Send22CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Send_2010)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createCancel23CreationTool() { + List/**/types = new ArrayList/**/(2); + types.add(ModelingElementTypes.Cancel_2009); + types.add(ModelingElementTypes.Cancel_2022); + NodeToolEntry entry = new NodeToolEntry( + Messages.Cancel23CreationTool_title, + Messages.Cancel23CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Cancel_2009)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createContent24CreationTool() { + List/**/types = new ArrayList/**/(5); + types.add(ModelingElementTypes.Content_2012); + types.add(ModelingElementTypes.Content_2013); + types.add(ModelingElementTypes.Content_2029); + types.add(ModelingElementTypes.Content_2043); + types.add(ModelingElementTypes.Content_2048); + NodeToolEntry entry = new NodeToolEntry( + Messages.Content24CreationTool_title, + Messages.Content24CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Content_2012)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createDonedata25CreationTool() { + List/**/types = new ArrayList/**/(1); + types.add(ModelingElementTypes.Donedata_2041); + NodeToolEntry entry = new NodeToolEntry( + Messages.Donedata25CreationTool_title, + Messages.Donedata25CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Donedata_2041)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createInvoke26CreationTool() { + List/**/types = new ArrayList/**/(1); + types.add(ModelingElementTypes.Invoke_2026); + NodeToolEntry entry = new NodeToolEntry( + Messages.Invoke26CreationTool_title, + Messages.Invoke26CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Invoke_2026)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private ToolEntry createFinalize27CreationTool() { + List/**/types = new ArrayList/**/(1); + types.add(ModelingElementTypes.Finalize_2027); + NodeToolEntry entry = new NodeToolEntry( + Messages.Finalize27CreationTool_title, + Messages.Finalize27CreationTool_desc, types); + entry.setSmallIcon(ModelingElementTypes + .getImageDescriptor(ModelingElementTypes.Finalize_2027)); + entry.setLargeIcon(entry.getSmallIcon()); + return entry; + } + + /** + * @generated + */ + private static class NodeToolEntry extends ToolEntry { + + /** + * @generated + */ + private final List elementTypes; + + /** + * @generated + */ + private NodeToolEntry(String title, String description, + List elementTypes) { + super(title, description, null, null); + this.elementTypes = elementTypes; + } + + /** + * @generated + */ + public Tool createTool() { + Tool tool = new UnspecifiedTypeCreationTool(elementTypes); + tool.setProperties(getToolProperties()); + return tool; + } + } + + /** + * @generated + */ + private static class LinkToolEntry extends ToolEntry { + + /** + * @generated + */ + private final List relationshipTypes; + + /** + * @generated + */ + private LinkToolEntry(String title, String description, + List relationshipTypes) { + super(title, description, null, null); + this.relationshipTypes = relationshipTypes; + } + + /** + * @generated + */ + public Tool createTool() { + Tool tool = new UnspecifiedTypeConnectionTool(relationshipTypes); + tool.setProperties(getToolProperties()); + return tool; + } + } +} Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingPaletteFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingUriEditorInputTester.java URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingUriEditorInputTester.java?rev=945691&view=auto ============================================================================== --- commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingUriEditorInputTester.java (added) +++ commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingUriEditorInputTester.java Tue May 18 15:13:13 2010 @@ -0,0 +1,23 @@ +package org.apache.commons.scxml.modeling.diagram.part; + +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.emf.common.ui.URIEditorInput; + +/** + * @generated + */ +public class ModelingUriEditorInputTester extends PropertyTester { + + /** + * @generated + */ + public boolean test(Object receiver, String method, Object[] args, + Object expectedValue) { + if (false == receiver instanceof URIEditorInput) { + return false; + } + URIEditorInput editorInput = (URIEditorInput) receiver; + return "modeling_diagram".equals(editorInput.getURI().fileExtension()); //$NON-NLS-1$ + } + +} Propchange: commons/sandbox/gsoc/2010/scxml-eclipse/trunk/src/main/java/org.apache.commons.scxml.diagram/src/org/apache/commons/scxml/modeling/diagram/part/ModelingUriEditorInputTester.java ------------------------------------------------------------------------------ svn:eol-style = native