Kaynağa Gözat

Merge pull request #624 from Yakindu/creation_wizard

Provide a simple possibility to extend the CreationWizard
jdicks 9 yıl önce
ebeveyn
işleme
1f13c98a3f

+ 1 - 0
plugins/org.yakindu.sct.ui.editor/plugin.xml

@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?eclipse version="3.4"?>
 <plugin>
+   <extension-point id="org.yakindu.sct.ui.wizard.create.contribution" name="SCT CReate Wizard Contribution" schema="schema/org.yakindu.sct.ui.wizard.create.contribution.exsd"/>
     <!-- Editor -->
   
    <extension

+ 102 - 0
plugins/org.yakindu.sct.ui.editor/schema/org.yakindu.sct.ui.wizard.create.contribution.exsd

@@ -0,0 +1,102 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.yakindu.sct.ui.editor" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+      <appinfo>
+         <meta.schema plugin="org.yakindu.sct.ui.editor" id="org.yakindu.sct.ui.wizard.create.contribution" name="SCT CReate Wizard Contribution"/>
+      </appinfo>
+      <documentation>
+         [Enter description of this extension point.]
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <annotation>
+         <appinfo>
+            <meta.element />
+         </appinfo>
+      </annotation>
+      <complexType>
+         <sequence minOccurs="0" maxOccurs="1">
+            <element ref="class"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute translatable="true"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="class">
+      <complexType>
+         <attribute name="class" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute kind="java" basedOn=":org.yakindu.sct.ui.editor.wizards.CreationWizardContribution"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="since"/>
+      </appinfo>
+      <documentation>
+         [Enter the first release in which this extension point appears.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="examples"/>
+      </appinfo>
+      <documentation>
+         [Enter extension point usage example here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="apiinfo"/>
+      </appinfo>
+      <documentation>
+         [Enter API information here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="implementation"/>
+      </appinfo>
+      <documentation>
+         [Enter information about supplied implementation of this extension point.]
+      </documentation>
+   </annotation>
+
+
+</schema>

+ 51 - 7
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/wizards/CreationWizard.java

@@ -97,25 +97,57 @@ public class CreationWizard extends Wizard implements INewWizard {
 
 	@Override
 	public void addPages() {
+		initModelCreationPage();
+		
+		initDomainWizardPage();
+
+	}
+
+	protected void initModelCreationPage() {
 		modelCreationPage = new ModelCreationWizardPage("DiagramModelFile", getSelection(), "sct");
 		modelCreationPage.setTitle("YAKINDU SCT Diagram");
 		modelCreationPage.setDescription("Create a new YAKINDU SCT Diagram File");
 		modelCreationPage.setImageDescriptor(StatechartImages.LOGO.imageDescriptor());
+		addPage(modelCreationPage);
+	}
+
+	protected void initDomainWizardPage() {
 		domainWizardPage = new DomainWizardPage("DomainWizard");
 		domainWizardPage.setTitle("Select Statechart Domain");
 		domainWizardPage.setDescription("Select the domain you want to create a statechart for.");
 		domainWizardPage.setImageDescriptor(StatechartImages.LOGO.imageDescriptor());
 		addPage(domainWizardPage);
-
-		addPage(modelCreationPage);
 	}
 
+	public static class DiagramCreationDesccription{
+ 
+		private URI uri;
+		private String domainID;
+
+		public DiagramCreationDesccription(URI uri, String domainID) {
+			this.uri = uri;
+			this.domainID = domainID;
+		}
+
+		public URI getModelURI() {
+			return uri;
+		}
+
+		public String getDomainID() {
+			return domainID;
+		}
+		
+	}
+	
 	@Override
 	public boolean performFinish() {
+		final DiagramCreationDesccription create = getDiagramDescription();
+		
 		IRunnableWithProgress op = new WorkspaceModifyOperation(null) {
 			@Override
 			protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException {
-				diagram = createDiagram(modelCreationPage.getURI(), modelCreationPage.getURI(), monitor);
+				
+				diagram = createDiagram(create, monitor);
 				if (isOpenOnCreate() && diagram != null) {
 					try {
 						openDiagram(diagram);
@@ -135,6 +167,17 @@ public class CreationWizard extends Wizard implements INewWizard {
 		return diagram != null;
 	}
 
+	protected DiagramCreationDesccription getDiagramDescription() {
+		URI uri = modelCreationPage.getURI();
+		final String domainID = domainWizardPage != null ? domainWizardPage.getDomainID()
+				: BasePackage.Literals.DOMAIN_ELEMENT__DOMAIN_ID.getDefaultValueLiteral();
+		
+		final DiagramCreationDesccription create = new DiagramCreationDesccription(uri,domainID);
+		return create;
+	}
+
+	
+
 	protected boolean openDiagram(Resource diagram) throws PartInitException {
 		String path = diagram.getURI().toPlatformString(true);
 		IResource workspaceResource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(path));
@@ -173,10 +216,12 @@ public class CreationWizard extends Wizard implements INewWizard {
 		return StatechartDiagramEditor.ID;
 	}
 
-	protected Resource createDiagram(final URI diagramURI, final URI modelURI, IProgressMonitor progressMonitor) {
+	protected Resource createDiagram(final DiagramCreationDesccription create, IProgressMonitor progressMonitor) {
 		TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain();
 		progressMonitor.beginTask("Creating diagram file ...", 3);
-		final Resource resource = editingDomain.getResourceSet().createResource(modelURI);
+		
+		final Resource resource = editingDomain.getResourceSet().createResource(create.getModelURI());
+		
 		AbstractTransactionalCommand command = new AbstractTransactionalCommand(editingDomain,
 				"Creating diagram file ...", Collections.EMPTY_LIST) {
 			@Override
@@ -186,8 +231,7 @@ public class CreationWizard extends Wizard implements INewWizard {
 				FactoryUtils.createStatechartModel(resource, preferencesHint);
 				Statechart statechart = (Statechart) EcoreUtil.getObjectByType(resource.getContents(),
 						SGraphPackage.Literals.STATECHART);
-				statechart.setDomainID(domainWizardPage != null ? domainWizardPage.getDomainID()
-						: BasePackage.Literals.DOMAIN_ELEMENT__DOMAIN_ID.getDefaultValueLiteral());
+				statechart.setDomainID(create.getDomainID());
 
 				try {
 					resource.save(getSaveOptions());

+ 23 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/wizards/CreationWizardContribution.java

@@ -0,0 +1,23 @@
+/**
+ * Copyright (c) 2010 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.ui.editor.wizards;
+
+import org.eclipse.swt.widgets.Composite;
+/**
+ * 
+ * @author Johannes Dicks - Initial contribution and API
+ * 
+ */
+public interface CreationWizardContribution {
+
+	void toDomainWizardPage(Composite composite);
+
+}

+ 27 - 18
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/wizards/DomainWizardPage.java

@@ -10,6 +10,11 @@
  */
 package org.yakindu.sct.ui.editor.wizards;
 
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.jface.viewers.ArrayContentProvider;
@@ -21,17 +26,12 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.program.Program;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Label;
 import org.yakindu.base.base.BasePackage;
 import org.yakindu.sct.domain.extension.DomainRegistry;
 import org.yakindu.sct.domain.extension.IDomainDescriptor;
-import org.yakindu.sct.ui.editor.StatechartImages;
 
 /**
  * 
@@ -46,8 +46,14 @@ public class DomainWizardPage extends WizardPage {
 
 	private Label image;
 
+	private Object domainDescriptors;
+
 	protected DomainWizardPage(String pageName) {
+		this(pageName, DomainRegistry.getDomainDescriptors());
+	}
+	protected DomainWizardPage(String pageName, List<IDomainDescriptor> domainDescriptors) {
 		super(pageName);
+		this.domainDescriptors = domainDescriptors;
 	}
 
 	public void createControl(Composite parent) {
@@ -74,7 +80,7 @@ public class DomainWizardPage extends WizardPage {
 				return ((IDomainDescriptor) element).getName();
 			}
 		});
-		domainCombo.setInput(DomainRegistry.getDomainDescriptors());
+		domainCombo.setInput(domainDescriptors);
 
 		description = new Label(domainSelectionGroup, SWT.WRAP);
 		GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(description);
@@ -93,19 +99,22 @@ public class DomainWizardPage extends WizardPage {
 		domainCombo.setSelection(new StructuredSelection(DomainRegistry
 				.getDomainDescriptor(BasePackage.Literals.DOMAIN_ELEMENT__DOMAIN_ID.getDefaultValueLiteral())));
 
-		Label spacer2 = new Label(domainSelectionGroup, SWT.NONE);
-		GridDataFactory.fillDefaults().span(2, 1).applyTo(spacer2);
-		
-		Label image = new Label(composite, SWT.NONE);
-		GridDataFactory.fillDefaults().grab(false, false).align(GridData.CENTER, GridData.CENTER).span(2, 1)
-				.applyTo(image);
-		image.setImage(StatechartImages.PRO_EDITION.image());
-		image.addMouseListener(new MouseAdapter() {
-			@Override
-			public void mouseDown(MouseEvent e) {
-				Program.launch("http://statecharts.org/pro.html");
+		IConfigurationElement[] configurationElements = Platform.getExtensionRegistry()
+				.getConfigurationElementsFor("org.yakindu.sct.ui.wizard.create.contribution");
+		if (configurationElements.length > 0) {
+
+			Label spacer2 = new Label(domainSelectionGroup, SWT.NONE);
+			GridDataFactory.fillDefaults().span(2, 1).applyTo(spacer2);
+			for (IConfigurationElement iConfigurationElement : configurationElements) {
+				try {
+					CreationWizardContribution contribution = (CreationWizardContribution) iConfigurationElement
+							.createExecutableExtension("class");
+					contribution.toDomainWizardPage(composite);
+				} catch (CoreException e) {
+					e.printStackTrace();
+				}
 			}
-		});
+		}
 	}
 
 	public String getDomainID() {