Browse Source

Standard license (#1494)

* Delegate to OSGI Service for domain status check

* Added Domain Status UI Integration for Infos

* Create Info and Warning Marker for Status
Andreas Mülder 8 years ago
parent
commit
a91587e59c

+ 1 - 0
plugins/org.yakindu.sct.domain.generic/META-INF/MANIFEST.MF

@@ -13,3 +13,4 @@ Require-Bundle: org.eclipse.core.runtime,
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-ActivationPolicy: lazy
 Export-Package: org.yakindu.sct.domain.generic
+Service-Component: OSGI-INF/component.xml

+ 5 - 0
plugins/org.yakindu.sct.domain.generic/OSGI-INF/component.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.yakindu.sct.domain.generic">
+   <implementation class="org.yakindu.sct.domain.generic.GenericDomainStatusProvider"/>
+   <reference bind="bindProvider" cardinality="0..1" interface="org.yakindu.sct.domain.extension.IDomainStatusProvider" name="IDomainStatusProvider" policy="dynamic" unbind="unbindProvider"/>
+</scr:component>

+ 2 - 1
plugins/org.yakindu.sct.domain.generic/build.properties

@@ -3,4 +3,5 @@ output.. = bin/
 bin.includes = META-INF/,\
                .,\
                plugin.xml,\
-               icons/
+               icons/,\
+               OSGI-INF/

+ 1 - 0
plugins/org.yakindu.sct.domain.generic/plugin.xml

@@ -6,6 +6,7 @@
       <Domain
             description="The default domain for YAKINDU Statechart Tools."
             domainID="org.yakindu.domain.default"
+            domainStatusProvider="org.yakindu.sct.domain.generic.GenericDomainStatusProvider"
             image="icons/logo_small.png"
             name="Default">
       </Domain>

+ 42 - 0
plugins/org.yakindu.sct.domain.generic/src/org/yakindu/sct/domain/generic/GenericDomainStatusProvider.java

@@ -0,0 +1,42 @@
+/** 
+ * Copyright (c) 2017 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.domain.generic;
+
+import java.util.Map;
+
+import org.yakindu.sct.domain.extension.DomainStatus;
+import org.yakindu.sct.domain.extension.IDomainStatusProvider;
+
+/**
+ * @author Thomas Kutz - Initial contribution and API
+ * 
+ */
+public class GenericDomainStatusProvider implements IDomainStatusProvider {
+
+	private static IDomainStatusProvider delegate;
+	
+	@Override
+	public DomainStatus getDomainStatus() {
+		if (delegate != null) {
+			return delegate.getDomainStatus();
+		}
+		return DomainStatus.OK;
+	}
+	
+	public void bindProvider(IDomainStatusProvider provider, Map<String, Object> properties) {
+		delegate = provider;
+	}
+	
+	public void unbindProvider(IDomainStatusProvider provider) {
+		delegate = null;
+	}
+
+}

+ 1 - 1
plugins/org.yakindu.sct.domain/src/org/yakindu/sct/domain/extension/DomainStatus.java

@@ -19,7 +19,7 @@ public class DomainStatus {
 	public static final DomainStatus OK = new DomainStatus(Severity.OK);
 
 	public static enum Severity {
-		OK, ERROR
+		OK, ERROR, WARNING, INFO
 	}
 
 	private Severity status;

+ 7 - 1
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/validation/DomainValidator.java

@@ -42,9 +42,15 @@ public class DomainValidator implements EValidator {
 	public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
 		if (eObject instanceof DomainElement) {
 			DomainStatus status = DomainRegistry.getDomainStatus(((DomainElement) eObject).getDomainID());
-			if (status.getSeverity() != Severity.OK) {
+			if (status.getSeverity() == Severity.ERROR) {
 				diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, "DomainValidator", 0, status.getMessage(),
 						new Object[] { eObject }));
+			} else if (status.getSeverity() == Severity.WARNING) {
+				diagnostics.add(new BasicDiagnostic(Diagnostic.WARNING, "DomainValidator", 0, status.getMessage(),
+						new Object[] { eObject }));
+			} else if (status.getSeverity() == Severity.INFO) {
+				diagnostics.add(new BasicDiagnostic(Diagnostic.INFO, "DomainValidator", 0, status.getMessage(),
+						new Object[] { eObject }));
 			}
 		}
 		return true;

+ 100 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editor/DomainStatusLabel.java

@@ -0,0 +1,100 @@
+/** 
+ * Copyright (c) 2017 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.editor;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.program.Program;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.yakindu.sct.domain.extension.DomainStatus;
+import org.yakindu.sct.domain.extension.DomainStatus.Severity;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class DomainStatusLabel extends Composite {
+
+	private static final Font DOMAIN_STATUS_FONT = new Font(null, new FontData("Verdana", 10, SWT.BOLD));
+	private static final String LICENCE_LINK = "http://www.statecharts.org/licences?source=product";
+
+	private CLabel label;
+	private Link link;
+
+	public DomainStatusLabel(DomainStatus status, Composite parent) {
+		super(parent, SWT.BORDER);
+		RowLayout layout = new RowLayout(SWT.HORIZONTAL);
+		setLayout(layout);
+		setBackground(ColorConstants.white);
+		createLabel(status);
+		createLink(status);
+	}
+
+	protected void createLink(DomainStatus status) {
+		link = new Link(this, SWT.NONE);
+		link.setFont(DOMAIN_STATUS_FONT);
+		link.setBackground(ColorConstants.white);
+		link.setText(getMessage(status));
+		link.setForeground(getSeverityColor(status.getSeverity()));
+		link.addSelectionListener(new SelectionAdapter() {
+			@Override
+			public void widgetSelected(SelectionEvent e) {
+				Program.launch(LICENCE_LINK);
+			}
+		});
+	}
+
+	protected void createLabel(DomainStatus status) {
+		label = new CLabel(this, SWT.NONE);
+		label.setFont(DOMAIN_STATUS_FONT);
+		label.setBackground(ColorConstants.white);
+		label.setForeground(getSeverityColor(status.getSeverity()));
+		label.setImage(getSeverityImage(status.getSeverity()));
+	}
+
+	protected String getMessage(DomainStatus domainStatus) {
+		if (domainStatus.getSeverity() == Severity.ERROR)
+			return domainStatus.getMessage() + " - editor is in readonly mode.";
+		return domainStatus.getMessage();
+
+	}
+
+	protected Color getSeverityColor(Severity severity) {
+		if (severity == Severity.ERROR)
+			return ColorConstants.red;
+		else if (severity == Severity.WARNING)
+			return ColorConstants.darkBlue;
+		return ColorConstants.darkBlue;
+	}
+
+	protected Image getSeverityImage(Severity severity) {
+		if (severity == Severity.ERROR) {
+			return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
+		} else if (severity == Severity.WARNING) {
+			return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK);
+		}
+		return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_INFO_TSK);
+
+	}
+
+}

+ 6 - 18
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editor/StatechartDiagramEditor.java

@@ -16,7 +16,6 @@ import org.eclipse.core.resources.IProjectDescription;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.draw2d.ColorConstants;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.transaction.TransactionalEditingDomain;
 import org.eclipse.gef.KeyHandler;
@@ -33,14 +32,10 @@ import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CLabel;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.FontData;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorSite;
 import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.ISharedImages;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.help.IWorkbenchHelpSystem;
@@ -74,7 +69,6 @@ import com.google.inject.Key;
 public class StatechartDiagramEditor extends DiagramPartitioningEditor implements IGotoMarker {
 
 	private static final int INITIAL_PALETTE_SIZE = 175;
-	private static final Font INVALID_DOMAIN_FONT = new Font(null, new FontData("Verdana", 10, SWT.BOLD));
 	public static final String ID = "org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor";
 
 	private KeyHandler keyHandler;
@@ -108,20 +102,14 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
 	@Override
 	protected void createBreadcrumbViewer(Composite parent) {
 		DomainStatus domainStatus = getDomainStatus();
-		if (domainStatus != null && domainStatus.getSeverity() == Severity.ERROR) {
+		if (domainStatus != null && !(domainStatus.getSeverity() == Severity.OK)) {
 			createStatusLabel(parent, domainStatus);
-			return;
 		}
 		super.createBreadcrumbViewer(parent);
 	}
 
-	private void createStatusLabel(Composite parent, DomainStatus domainStatus) {
-		CLabel label = new CLabel(parent, SWT.SHADOW_OUT);
-		label.setFont(INVALID_DOMAIN_FONT);
-		label.setBackground(ColorConstants.white);
-		label.setForeground(ColorConstants.red);
-		label.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
-		label.setText(domainStatus.getMessage() + " - editor is in readonly mode.");
+	protected void createStatusLabel(Composite parent, DomainStatus domainStatus) {
+		DomainStatusLabel label = new DomainStatusLabel(domainStatus, parent);
 		GridDataFactory.fillDefaults().grab(true, false).applyTo(label);
 		parent.pack(true);
 	}
@@ -231,8 +219,8 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
 	}
 
 	/**
-	 * Overrides the GMF key handler to fix key binding for zooming and to
-	 * remove unused key bindings.
+	 * Overrides the GMF key handler to fix key binding for zooming and to remove
+	 * unused key bindings.
 	 */
 	@Override
 	protected KeyHandler getKeyHandler() {
@@ -240,7 +228,7 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
 			keyHandler = new KeyHandler();
 
 			registerZoomActions();
-			
+
 			// Zoom in - Unix - Numpad plus
 			getKeyHandler().put(KeyStroke.getPressed('+', SWT.KEYPAD_ADD, SWT.MOD1),
 					getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));