Browse Source

Major refactoring of Xtext Utils JFace/GMF.

- Renamed XtextStyledText to StyledTextXtextAdapter
- Refactored StyledTextXtextAdapter to use specific XtextSourceViewerEx, which can hook onto an existing StyledText. Separated resource handling into a XtextFakeResourceContext and added contract (IXtextContextFakeResourceProvider) to handle population of fake resource set. Further, moved all content assistent related stuff into the CompletionProposalAdapter, so that it can be used as in the simple JFace case.
- Refactored PropertyDescriptors use applyLayout in a more consistent way.
Alexander Nyßen 14 years ago
parent
commit
c312fe4d2a

+ 2 - 5
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/breadcrumb/BreadcrumbEditorUtil.java

@@ -15,7 +15,6 @@ import java.util.List;
 
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.resources.IFile;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IFileEditorInput;
@@ -24,7 +23,7 @@ import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor;
 
-import de.itemis.xtext.utils.jface.viewers.util.ActiveEditorResolver;
+import de.itemis.xtext.utils.jface.viewers.util.ActiveEditorTracker;
 
 /**
  * 
@@ -37,9 +36,7 @@ public class BreadcrumbEditorUtil {
 		if (!file.exists()) {
 			return;
 		}
-		ActiveEditorResolver resolver = new ActiveEditorResolver();
-		Display.getDefault().syncExec(resolver);
-		IEditorPart result = resolver.getResult();
+		IEditorPart result = ActiveEditorTracker.getLastActiveEditor();
 		List<IFile> newHistory = new ArrayList<IFile>();
 		if (result instanceof BreadcrumbDiagramEditor) {
 			List<IFile> history = ((BreadcrumbDiagramEditor) result)

+ 2 - 5
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/propertysheets/AbstractEditorPropertySection.java

@@ -5,7 +5,6 @@ import org.eclipse.emf.ecore.EClass;
 import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.edit.domain.EditingDomain;
 import org.eclipse.emf.edit.domain.IEditingDomainProvider;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IEditorPart;
 import org.yakindu.sct.ui.editor.extensions.Extensions;
 import org.yakindu.sct.ui.editor.extensions.IExpressionsProvider;
@@ -14,7 +13,7 @@ import com.google.inject.Injector;
 
 import de.itemis.gmf.runtime.commons.properties.GenericFormBasedPropertySection;
 import de.itemis.gmf.runtime.commons.properties.descriptors.XtextPropertyDescriptor;
-import de.itemis.xtext.utils.jface.viewers.util.ActiveEditorResolver;
+import de.itemis.xtext.utils.jface.viewers.util.ActiveEditorTracker;
 
 /**
  * 
@@ -29,9 +28,7 @@ public abstract class AbstractEditorPropertySection extends
 	 * scoping to elements outside the text block
 	 */
 	protected Resource getActiveEditorResource() {
-		ActiveEditorResolver activeEditorResolver = new ActiveEditorResolver();
-		Display.getDefault().syncExec(activeEditorResolver);
-		IEditorPart editor = activeEditorResolver.getResult();
+		IEditorPart editor = ActiveEditorTracker.getLastActiveEditor();
 
 		EditingDomain domain = null;
 		if (editor instanceof IEditingDomainProvider) {

+ 8 - 4
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/propertysheets/StatePropertySection.java

@@ -10,6 +10,7 @@
  */
 package org.yakindu.sct.ui.editor.propertysheets;
 
+import java.util.Collections;
 import java.util.List;
 
 import org.yakindu.sct.model.sgraph.SGraphPackage;
@@ -19,6 +20,7 @@ import org.yakindu.sct.ui.editor.utils.IYakinduSctHelpContextIds;
 import de.itemis.gmf.runtime.commons.properties.descriptors.IFormPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.TextPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.XtextPropertyDescriptor;
+import de.itemis.xtext.utils.jface.viewers.context.CloningBasedFakeContextResourcesProvider;
 
 /**
  * Property Section for {@link StateEditPart}s. Consists of a
@@ -37,11 +39,13 @@ public class StatePropertySection extends NamePropertySection {
 
 		XtextPropertyDescriptor expressionsDescriptor = new XtextPropertyDescriptor(
 				SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
-				"Expression: ", getInjector(SGraphPackage.Literals.STATE),
-				getActiveEditorResource(),
-				IYakinduSctHelpContextIds.SC_PROPERTIES_STATE_EXPRESSION);
+				"Expression: ",
+				IYakinduSctHelpContextIds.SC_PROPERTIES_STATE_EXPRESSION,
+				getInjector(SGraphPackage.Literals.STATE),
+				new CloningBasedFakeContextResourcesProvider(
+						Collections.singletonList(getActiveEditorResource())));
 		descriptors.add(expressionsDescriptor);
-		
+
 		// Submachine reference
 		SubmachineSelectionDialogPropertyDescriptor submachineDescriptor = new SubmachineSelectionDialogPropertyDescriptor();
 		descriptors.add(submachineDescriptor);

+ 8 - 4
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/propertysheets/StatechartPropertySection.java

@@ -19,6 +19,7 @@ import org.yakindu.sct.ui.editor.utils.IYakinduSctHelpContextIds;
 import de.itemis.gmf.runtime.commons.properties.descriptors.IFormPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.TextPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.XtextPropertyDescriptor;
+import de.itemis.xtext.utils.jface.viewers.context.IXtextContextFakeResourcesProvider;
 
 /**
  * Property Section for {@link StatechartTextEditPart}s. Consists of a
@@ -37,12 +38,15 @@ public class StatechartPropertySection extends AbstractEditorPropertySection {
 		TextPropertyDescriptor nameDescriptor = new TextPropertyDescriptor(
 				SGraphPackage.Literals.NAMED_ELEMENT__NAME, "Name: ");
 		descriptors.add(nameDescriptor);
-		// Text property descriptor for the expression
+		
+		// Xtext property descriptor for the expression
 		XtextPropertyDescriptor expressionsDescriptor = new XtextPropertyDescriptor(
 				SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
-				"Expression: ", getInjector(SGraphPackage.Literals.STATECHART),
-				IYakinduSctHelpContextIds.SC_PROPERTIES_STATECHART_EXPRESSION);
+				"Expression: ",
+				IYakinduSctHelpContextIds.SC_PROPERTIES_STATECHART_EXPRESSION,
+				getInjector(SGraphPackage.Literals.STATECHART),
+				IXtextContextFakeResourcesProvider.NULL_CONTEXT_PROVIDER);
 		descriptors.add(expressionsDescriptor);
 	}
-	
+
 }

+ 7 - 4
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/propertysheets/TransitionPropertySection.java

@@ -10,6 +10,7 @@
  */
 package org.yakindu.sct.ui.editor.propertysheets;
 
+import java.util.Collections;
 import java.util.List;
 
 import org.yakindu.sct.model.sgraph.SGraphPackage;
@@ -18,6 +19,7 @@ import org.yakindu.sct.ui.editor.utils.IYakinduSctHelpContextIds;
 
 import de.itemis.gmf.runtime.commons.properties.descriptors.IFormPropertyDescriptor;
 import de.itemis.gmf.runtime.commons.properties.descriptors.XtextPropertyDescriptor;
+import de.itemis.xtext.utils.jface.viewers.context.CloningBasedFakeContextResourcesProvider;
 
 /**
  * Property Section for {@link TransitionEditPart}s. Consists of a
@@ -33,10 +35,11 @@ public class TransitionPropertySection extends AbstractEditorPropertySection {
 			List<IFormPropertyDescriptor> descriptors) {
 		XtextPropertyDescriptor expressionsDescriptor = new XtextPropertyDescriptor(
 				SGraphPackage.Literals.EXPRESSION_ELEMENT__EXPRESSION,
-				"Expression: ", getInjector(SGraphPackage.Literals.TRANSITION),
-				getActiveEditorResource(),
-				IYakinduSctHelpContextIds.SC_PROPERTIES_TRANSITION_EXPRESSION);
+				"Expression: ",
+				IYakinduSctHelpContextIds.SC_PROPERTIES_TRANSITION_EXPRESSION,
+				getInjector(SGraphPackage.Literals.TRANSITION),
+				new CloningBasedFakeContextResourcesProvider(
+						Collections.singletonList(getActiveEditorResource())));
 		descriptors.add(expressionsDescriptor);
-
 	}
 }

+ 4 - 4
plugins/org.yakindu.sct.ui.navigator/src/org/yakindu/sct/ui/navigator/NavigatorLinkHelper.java

@@ -36,12 +36,12 @@ import org.eclipse.ui.navigator.ILinkHelper;
 import org.eclipse.ui.part.FileEditorInput;
 import org.yakindu.sct.ui.navigator.utils.ComposedAdapterFactoryUtil;
 
-import de.itemis.xtext.utils.jface.viewers.util.ActiveEditorResolver;
+import de.itemis.xtext.utils.jface.viewers.util.ActiveEditorTracker;
 
 /**
  * 
  * @author m.muehlbrandt
- *
+ * 
  */
 public class NavigatorLinkHelper implements ILinkHelper {
 
@@ -73,7 +73,7 @@ public class NavigatorLinkHelper implements ILinkHelper {
 	}
 
 	public IStructuredSelection findSelection(IEditorInput anInput) {
-		IEditorPart activeEditor = ActiveEditorResolver.getActiveEditor();
+		IEditorPart activeEditor = ActiveEditorTracker.getLastActiveEditor();
 		if (activeEditor instanceof DiagramDocumentEditor) {
 			Diagram diagram = ((DiagramDocumentEditor) activeEditor)
 					.getDiagram();
@@ -86,7 +86,7 @@ public class NavigatorLinkHelper implements ILinkHelper {
 		}
 		return StructuredSelection.EMPTY;
 	}
-	
+
 	public void activateEditor(IWorkbenchPage aPage,
 			IStructuredSelection aSelection) {