Pārlūkot izejas kodu

Issue 1098 (#1102)

* added preference page to change the remote branch location

* * sort examples by title * #1098
Andreas Mülder 8 gadi atpakaļ
vecāks
revīzija
13c25ad808

+ 4 - 0
plugins/org.yakindu.sct.examples.wizard/src/org/yakindu/sct/examples/wizard/preferences/ExamplesPreferenceConstants.java

@@ -18,4 +18,8 @@ package org.yakindu.sct.examples.wizard.preferences;
 public interface ExamplesPreferenceConstants {
 
 	public static final String STORAGE_LOCATION = "storageLocation";
+	
+	public static final String REMOTE_LOCATION = "remoteLocation";
+	
+	public static final String REMOTE_BRANCH = "remoteBranch";
 }

+ 2 - 0
plugins/org.yakindu.sct.examples.wizard/src/org/yakindu/sct/examples/wizard/preferences/ExamplesPreferenceInitializer.java

@@ -30,6 +30,8 @@ public class ExamplesPreferenceInitializer extends AbstractPreferenceInitializer
 		String property = System.getProperty("user.home");
 		getPreferenceStore().setDefault(ExamplesPreferenceConstants.STORAGE_LOCATION,
 				property + File.separator + EXAMPLES);
+		getPreferenceStore().setDefault(ExamplesPreferenceConstants.REMOTE_LOCATION, "https://github.com/Yakindu/examples");
+		getPreferenceStore().setDefault(ExamplesPreferenceConstants.REMOTE_BRANCH, "release");
 	}
 
 	protected IPreferenceStore getPreferenceStore() {

+ 23 - 36
plugins/org.yakindu.sct.examples.wizard/src/org/yakindu/sct/examples/wizard/preferences/ExamplesPreferencePage.java

@@ -13,11 +13,11 @@ package org.yakindu.sct.examples.wizard.preferences;
 import org.eclipse.jface.preference.DirectoryFieldEditor;
 import org.eclipse.jface.preference.FieldEditorPreferencePage;
 import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.StringFieldEditor;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
 import org.yakindu.sct.examples.wizard.ExampleActivator;
@@ -28,14 +28,14 @@ import org.yakindu.sct.examples.wizard.ExampleActivator;
  */
 public class ExamplesPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
 
-	private static class StorageLocationFieldEditor extends DirectoryFieldEditor {
-		
+	protected static class StorageLocationFieldEditor extends DirectoryFieldEditor {
+
 		public StorageLocationFieldEditor(String name, String labelText, Composite parent) {
 			super(name, labelText, parent);
 			setEmptyStringAllowed(false);
 			setErrorMessage("Storage location must not be empty.");
 		}
-		
+
 		/**
 		 * Checks only if the input text is not empty, but not if the directory
 		 * exists as in that case it will be created by the example wizard.
@@ -43,14 +43,15 @@ public class ExamplesPreferencePage extends FieldEditorPreferencePage implements
 		@Override
 		protected boolean doCheckState() {
 			String fileName = getTextControl().getText();
-	        fileName = fileName.trim();
+			fileName = fileName.trim();
 			if (fileName.length() == 0 && !isEmptyStringAllowed()) {
 				return false;
 			}
 			return true;
 		}
+
 	};
-	
+
 	public ExamplesPreferencePage() {
 		super(GRID);
 		setDescription("Examples Preference Page");
@@ -62,37 +63,23 @@ public class ExamplesPreferencePage extends FieldEditorPreferencePage implements
 		addFields(parent);
 	}
 
-	protected void addFields(Composite parent) {
-		Composite main = createPageLayout(parent);
-		createStorageLocationEditor(main);
-	}
-
-	private void createStorageLocationEditor(Composite main) {
-		Composite composite = createGroupComposite(main, "Storage Location");
-		addField(new StorageLocationFieldEditor(ExamplesPreferenceConstants.STORAGE_LOCATION,
-				"Storage Location:", composite));
-	}
-
-	protected Composite createPageLayout(Composite parent) {
-		Composite main = new Composite(parent, SWT.NULL);
-		main.setLayout(new GridLayout());
-		main.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
-		return main;
+	protected void addFields(Composite main) {
+		addField(new StorageLocationFieldEditor(ExamplesPreferenceConstants.STORAGE_LOCATION, "Storage Location:",
+				main));
+		separator();
+		StringFieldEditor remoteLocationEditor = new StringFieldEditor(ExamplesPreferenceConstants.REMOTE_LOCATION,
+				"Remote Location", main);
+		remoteLocationEditor.getTextControl(main).setEditable(false);
+		addField(remoteLocationEditor);
+		separator();
+		StringFieldEditor remoteBranchEditor = new StringFieldEditor(ExamplesPreferenceConstants.REMOTE_BRANCH,
+				"Remote Branch:", main);
+		addField(remoteBranchEditor);
 	}
 
-	protected Composite createGroupComposite(Composite parent, String title) {
-		Group group = new Group(parent, SWT.NONE);
-		group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-		group.setLayout(new GridLayout(3, false));
-		Composite composite = new Composite(group, SWT.NONE);
-		GridLayout gridLayout = new GridLayout(3, false);
-		composite.setLayout(gridLayout);
-		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
-		gridData.grabExcessHorizontalSpace = true;
-		gridData.horizontalSpan = 3;
-		composite.setLayoutData(gridData);
-		group.setText(title);
-		return composite;
+	private void separator() {
+		Label label = new Label(getFieldEditorParent(), SWT.NONE);
+		label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1));
 	}
 
 	public void init(IWorkbench workbench) {

+ 7 - 1
plugins/org.yakindu.sct.examples.wizard/src/org/yakindu/sct/examples/wizard/service/ExampleData.java

@@ -11,6 +11,7 @@
 package org.yakindu.sct.examples.wizard.service;
 
 import java.io.File;
+import java.text.Collator;
 import java.util.Arrays;
 
 /**
@@ -18,7 +19,7 @@ import java.util.Arrays;
  * @author t00manysecretss
  * 
  */
-public class ExampleData {
+public class ExampleData implements Comparable<ExampleData> {
 
 	private static final String PRO_EXAMPLE = "professional";
 	private String id;
@@ -149,4 +150,9 @@ public class ExampleData {
 		return true;
 	}
 
+	@Override
+	public int compareTo(ExampleData other) {
+		return Collator.getInstance().compare(this.title, other.title);
+	}
+
 }

+ 0 - 4
plugins/org.yakindu.sct.examples.wizard/src/org/yakindu/sct/examples/wizard/service/ExampleWizardModule.java

@@ -16,7 +16,6 @@ import org.yakindu.sct.examples.wizard.service.git.JsonMetaDataReader;
 
 import com.google.inject.Binder;
 import com.google.inject.Module;
-import com.google.inject.name.Names;
 
 /**
  * 
@@ -25,12 +24,9 @@ import com.google.inject.name.Names;
  */
 public class ExampleWizardModule implements Module {
 
-	public static final String REPOSITORY_URL = "repository_url";
-
 	@Override
 	public void configure(Binder binder) {
 		binder.bind(IExampleService.class).to(GitRepositoryExampleService.class);
-		binder.bindConstant().annotatedWith(Names.named(REPOSITORY_URL)).to("https://github.com/Yakindu/examples");
 		binder.bind(IExampleDataReader.class).to(JsonMetaDataReader.class);
 	}
 

+ 15 - 13
plugins/org.yakindu.sct.examples.wizard/src/org/yakindu/sct/examples/wizard/service/git/GitRepositoryExampleService.java

@@ -18,6 +18,7 @@ import java.nio.file.SimpleFileVisitor;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 import org.eclipse.core.resources.IFile;
@@ -41,12 +42,10 @@ import org.eclipse.ui.wizards.datatransfer.ImportOperation;
 import org.yakindu.sct.examples.wizard.ExampleActivator;
 import org.yakindu.sct.examples.wizard.preferences.ExamplesPreferenceConstants;
 import org.yakindu.sct.examples.wizard.service.ExampleData;
-import org.yakindu.sct.examples.wizard.service.ExampleWizardModule;
 import org.yakindu.sct.examples.wizard.service.IExampleService;
 
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
-import com.google.inject.name.Named;
 
 /**
  * 
@@ -62,11 +61,6 @@ public class GitRepositoryExampleService implements IExampleService {
 
 	private static final String METADATA_JSON = "metadata.json";
 
-	private static final String RELEASE = "release";
-
-	@Inject
-	@Named(ExampleWizardModule.REPOSITORY_URL)
-	private String repositoryURL;
 	@Inject
 	private IExampleDataReader reader;
 
@@ -102,27 +96,34 @@ public class GitRepositoryExampleService implements IExampleService {
 	}
 
 	protected IStatus updateRepository(IProgressMonitor monitor) {
+		String repoURL = getPreference(ExamplesPreferenceConstants.REMOTE_LOCATION);
 		try {
 			java.nio.file.Path storageLocation = getStorageLocation();
 			PullResult result = Git.open(storageLocation.toFile()).pull()
 					.setProgressMonitor(new EclipseGitProgressTransformer(monitor)).call();
 			if (!result.isSuccessful()) {
 				return new Status(IStatus.ERROR, ExampleActivator.PLUGIN_ID,
-						"Unable to update repository " + repositoryURL + "!");
+						"Unable to update repository " + repoURL + "!");
 			}
 		} catch (GitAPIException | IOException e) {
 			return new Status(IStatus.ERROR, ExampleActivator.PLUGIN_ID,
-					"Unable to update repository " + repositoryURL + "!");
+					"Unable to update repository " + repoURL + "!");
 		}
 		return Status.OK_STATUS;
 	}
-
+	
+	protected String getPreference(String constant){
+		return ExampleActivator.getDefault().getPreferenceStore().getString(constant);
+	}
+	
 	protected IStatus cloneRepository(IProgressMonitor monitor) {
+		String repoURL = getPreference(ExamplesPreferenceConstants.REMOTE_LOCATION);
+		String remoteBranch = getPreference(ExamplesPreferenceConstants.REMOTE_BRANCH);
 		Git call = null;
 		java.nio.file.Path storageLocation = getStorageLocation();
 		try {
-			call = Git.cloneRepository().setURI(repositoryURL).setDirectory(storageLocation.toFile())
-					.setProgressMonitor(new EclipseGitProgressTransformer(monitor)).setBranch(RELEASE).call();
+			call = Git.cloneRepository().setURI(repoURL).setDirectory(storageLocation.toFile())
+					.setProgressMonitor(new EclipseGitProgressTransformer(monitor)).setBranch(remoteBranch).call();
 		} catch (GitAPIException e) {
 			try {
 				deleteFolder(storageLocation);
@@ -130,7 +131,7 @@ public class GitRepositoryExampleService implements IExampleService {
 				ex.printStackTrace();
 			}
 			return new Status(IStatus.ERROR, ExampleActivator.PLUGIN_ID,
-					"Unable to clone repository " + repositoryURL + "!");
+					"Unable to clone repository " + repoURL + "!");
 		} finally {
 			if (call != null)
 				call.close();
@@ -151,6 +152,7 @@ public class GitRepositoryExampleService implements IExampleService {
 		List<java.nio.file.Path> projects = new ArrayList<>();
 		findMetaData(projects, storageLocation);
 		List<ExampleData> result = reader.parse(projects);
+		Collections.sort(result);
 		return result;
 	}
 

+ 13 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editor/StatechartDiagramEditor.java

@@ -14,7 +14,9 @@ import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IProjectDescription;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.draw2d.ColorConstants;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.transaction.TransactionalEditingDomain;
@@ -28,6 +30,7 @@ import org.eclipse.gmf.runtime.common.ui.services.marker.MarkerNavigationService
 import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
 import org.eclipse.gmf.runtime.diagram.ui.internal.parts.DiagramGraphicalViewerKeyHandler;
 import org.eclipse.gmf.runtime.gef.ui.internal.editparts.AnimatableZoomManager;
+import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.swt.SWT;
@@ -255,6 +258,16 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
 			// Zoom in - Windows - German layout ([CTRL++] propagates char 0x1d)
 			getKeyHandler().put(KeyStroke.getPressed((char) 0x1d, 0x2b, SWT.MOD1),
 					getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));
+			
+			// Test Error - for AERI testing only
+//			DOWN: stateMask=0x50000 CTRL ALT, keyCode=0x6c 'l', character=0xc ''
+			getKeyHandler().put(KeyStroke.getPressed((char)0xc, 0x6c,  0x50000), new Action() {
+				@Override
+				public void run() {
+					DiagramActivator.getDefault().getLog()
+							.log(new Status(IStatus.ERROR, DiagramActivator.PLUGIN_ID, "AERI Testing error"));
+				}
+			});
 
 		}
 		return keyHandler;