瀏覽代碼

#898 remove URIUtil, remove Image from extension point

Andreas Muelder 9 年之前
父節點
當前提交
03f14a81da

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

@@ -6,17 +6,13 @@ Bundle-Version: 2.7.1.qualifier
 Bundle-Activator: org.yakindu.sct.domain.DomainActivator
 Bundle-Vendor: statecharts.org
 Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.swt,
- org.eclipse.jface,
  com.google.guava,
  com.google.inject,
  org.eclipse.xtext,
- org.eclipse.core.resources,
  org.yakindu.base.types
 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
 Bundle-ActivationPolicy: lazy
 Export-Package: org.yakindu.sct.domain,
- org.yakindu.sct.domain.extension,
- org.yakindu.sct.domain.util
+ org.yakindu.sct.domain.extension
 Bundle-ClassPath: .
 Import-Package: com.google.inject.multibindings;version="1.3.0"

+ 3 - 8
plugins/org.yakindu.sct.domain/src/org/yakindu/sct/domain/extension/DomainRegistry.java

@@ -25,8 +25,6 @@ import org.eclipse.emf.ecore.resource.URIConverter;
 import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.eclipse.emf.ecore.xmi.XMIResource;
 import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.swt.graphics.Image;
 import org.eclipse.xtext.EcoreUtil2;
 import org.osgi.framework.Bundle;
 import org.yakindu.base.base.BasePackage;
@@ -58,7 +56,7 @@ public class DomainRegistry {
 
 		private final IConfigurationElement configElement;
 
-		private Image image;
+		private URL image;
 
 		private IDomainInjectorProvider injectorProvider;
 
@@ -95,17 +93,14 @@ public class DomainRegistry {
 		}
 
 		@Override
-		public Image getImage() {
+		public URL getImagePath() {
 			if (image != null)
 				return image;
 			String path = configElement.getAttribute(IMAGE);
 			if (path == null)
 				return null;
-
 			Bundle extensionBundle = Platform.getBundle(configElement.getContributor().getName());
-			URL entry = extensionBundle.getEntry(path);
-			ImageDescriptor descriptor = ImageDescriptor.createFromURL(entry);
-			image = descriptor.createImage();
+			image = extensionBundle.getEntry(path);
 			return image;
 		}
 	}

+ 2 - 2
plugins/org.yakindu.sct.domain/src/org/yakindu/sct/domain/extension/IDomainDescriptor.java

@@ -1,6 +1,6 @@
 package org.yakindu.sct.domain.extension;
 
-import org.eclipse.swt.graphics.Image;
+import java.net.URL;
 
 public interface IDomainDescriptor {
 
@@ -12,6 +12,6 @@ public interface IDomainDescriptor {
 
 	IDomainInjectorProvider getDomainInjectorProvider();
 
-	Image getImage();
+	URL getImagePath();
 
 }

+ 0 - 30
plugins/org.yakindu.sct.domain/src/org/yakindu/sct/domain/util/URIUtil.java

@@ -1,30 +0,0 @@
-/** 
- * Copyright (c) 2015 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.util;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.emf.common.util.URI;
-
-/**
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public class URIUtil {
-
-	public static IFile toFile(URI uri) {
-		if (uri.isPlatformResource()) {
-			String platformString = uri.toPlatformString(true);
-			return (IFile) ResourcesPlugin.getWorkspace().getRoot().findMember(platformString);
-		}
-		return null;
-	}
-}

+ 0 - 1
plugins/org.yakindu.sct.model.stext/META-INF/MANIFEST.MF

@@ -22,7 +22,6 @@ Require-Bundle: org.eclipse.xtext;visibility:=reexport,
  org.yakindu.sct.domain
 Import-Package: org.apache.commons.logging,
  org.apache.log4j,
- org.eclipse.xtext.builder.builderState,
  org.eclipse.xtext.xbase.lib
 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
 Export-Package: org.yakindu.sct.model.stext,

+ 10 - 2
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editor/SCTFileEditorOpener.java

@@ -11,6 +11,7 @@
 package org.yakindu.sct.ui.editor.editor;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.emf.ecore.EReference;
 import org.eclipse.ui.IEditorPart;
@@ -18,7 +19,6 @@ import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.part.FileEditorInput;
 import org.eclipse.xtext.ui.editor.IURIEditorOpener;
-import org.yakindu.sct.domain.util.URIUtil;
 
 /**
  * Opens <code>.sct</code> files in corresponding statechart diagramm editor.
@@ -31,7 +31,7 @@ public class SCTFileEditorOpener implements IURIEditorOpener {
 	@Override
 	public IEditorPart open(URI uri, boolean select) {
 		try {
-			IFile fileToOpen = URIUtil.toFile(uri);
+			IFile fileToOpen = toFile(uri);
 			if (fileToOpen != null) {
 				return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
 						.openEditor(new FileEditorInput(fileToOpen), StatechartDiagramEditor.ID);
@@ -46,5 +46,13 @@ public class SCTFileEditorOpener implements IURIEditorOpener {
 	public IEditorPart open(URI referenceOwnerURI, EReference reference, int indexInList, boolean select) {
 		return open(referenceOwnerURI, select);
 	}
+	
+	public IFile toFile(URI uri) {
+		if (uri.isPlatformResource()) {
+			String platformString = uri.toPlatformString(true);
+			return (IFile) ResourcesPlugin.getWorkspace().getRoot().findMember(platformString);
+		}
+		return null;
+	}
 
 }

+ 15 - 1
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/wizards/DomainWizardPage.java

@@ -17,6 +17,8 @@ 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.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
 import org.eclipse.jface.viewers.ArrayContentProvider;
 import org.eclipse.jface.viewers.ComboViewer;
 import org.eclipse.jface.viewers.ISelection;
@@ -26,12 +28,14 @@ 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.graphics.Image;
 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.DiagramActivator;
 
 /**
  * 
@@ -90,11 +94,20 @@ public class DomainWizardPage extends WizardPage {
 			public void selectionChanged(SelectionChangedEvent event) {
 				IDomainDescriptor domain = unwrap(event.getSelection());
 				description.setText(domain.getDescription());
-				image.setImage(domain.getImage());
+				image.setImage(asImage(domain));
 				domainSelectionGroup.layout();
 
 			}
 
+			private Image asImage(IDomainDescriptor domain) {
+				ImageRegistry imageRegistry = DiagramActivator.getDefault().getImageRegistry();
+				Image image = imageRegistry.get(domain.getImagePath().toString());
+				if (image == null)
+					imageRegistry.put(domain.getImagePath().toString(),
+							ImageDescriptor.createFromURL(domain.getImagePath()).createImage());
+				return imageRegistry.get(domain.getImagePath().toString());
+			}
+
 		});
 		domainCombo.setSelection(new StructuredSelection(DomainRegistry
 				.getDomainDescriptor(BasePackage.Literals.DOMAIN_ELEMENT__DOMAIN_ID.getDefaultValueLiteral())));
@@ -127,3 +140,4 @@ public class DomainWizardPage extends WizardPage {
 	}
 
 }
+