diff options
author | Juergen Haug | 2012-06-15 12:46:28 +0000 |
---|---|---|
committer | Juergen Haug | 2012-06-15 12:46:28 +0000 |
commit | db1daef4390d90ef1b3b9ede1f33f4312bcfdf74 (patch) | |
tree | c03941c03f79e5ae42ee03b2a327c7c03a5226a7 /plugins/org.eclipse.etrice.core.config.ui/src/org | |
parent | 5c1cfd9219168e79f77c779e9c0fb8d47feee790 (diff) | |
download | org.eclipse.etrice-db1daef4390d90ef1b3b9ede1f33f4312bcfdf74.tar.gz org.eclipse.etrice-db1daef4390d90ef1b3b9ede1f33f4312bcfdf74.tar.xz org.eclipse.etrice-db1daef4390d90ef1b3b9ede1f33f4312bcfdf74.zip |
[CQ 6485][config, generator, tests] merge attribute config
generator
Change-Id: Ia4e6538925ddced23555572065b78151c7373c92
Diffstat (limited to 'plugins/org.eclipse.etrice.core.config.ui/src/org')
6 files changed, 338 insertions, 102 deletions
diff --git a/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/ConfigUiModule.java b/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/ConfigUiModule.java index da536451c..8e8c33a62 100644 --- a/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/ConfigUiModule.java +++ b/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/ConfigUiModule.java @@ -1,15 +1,38 @@ -/* - * generated by Xtext - */ +/******************************************************************************* + * Copyright (c) 2012 protos software gmbh (http://www.protos.de). + * 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: + * Juergen Haug + * + *******************************************************************************/ package org.eclipse.etrice.core.ui; +import org.eclipse.etrice.core.ui.linking.GlobalNonPlatformURIEditorOpener; +import org.eclipse.etrice.core.ui.linking.ImportAwareHyperlinkHelper; import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper; /** * Use this class to register components to be used within the IDE. */ -public class ConfigUiModule extends org.eclipse.etrice.core.ui.AbstractConfigUiModule { +public class ConfigUiModule extends + org.eclipse.etrice.core.ui.AbstractConfigUiModule { public ConfigUiModule(AbstractUIPlugin plugin) { super(plugin); } + + // HOWTO: use URI imports - need special editor opener + public Class<? extends org.eclipse.xtext.ui.editor.IURIEditorOpener> bindIURIEditorOpener() { + return GlobalNonPlatformURIEditorOpener.class; + } + + // HOWTO: use URI imports - need special class for creating hyper links for + // imports + public Class<? extends IHyperlinkHelper> bindIHyperlinkHelper() { + return ImportAwareHyperlinkHelper.class; + } } diff --git a/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/contentassist/ConfigProposalProvider.java b/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/contentassist/ConfigProposalProvider.java index a40bceb19..4de9d8d4e 100644 --- a/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/contentassist/ConfigProposalProvider.java +++ b/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/contentassist/ConfigProposalProvider.java @@ -1,12 +1,225 @@ -/* -* generated by Xtext -*/ +/******************************************************************************* + * Copyright (c) 2012 protos software gmbh (http://www.protos.de). + * 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: + * Juergen Haug + * + *******************************************************************************/ package org.eclipse.etrice.core.ui.contentassist; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceProxy; +import org.eclipse.core.resources.IResourceProxyVisitor; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.etrice.core.config.ActorClassConfig; +import org.eclipse.etrice.core.config.ActorInstanceConfig; +import org.eclipse.etrice.core.config.AttrConfig; +import org.eclipse.etrice.core.config.RefPath; +import org.eclipse.etrice.core.config.util.ConfigUtil; +import org.eclipse.etrice.core.room.ActorContainerClass; +import org.eclipse.etrice.core.room.ActorContainerRef; +import org.eclipse.etrice.core.room.ActorRef; +import org.eclipse.etrice.core.room.LiteralType; +import org.eclipse.etrice.core.room.util.RoomHelpers; import org.eclipse.etrice.core.ui.contentassist.AbstractConfigProposalProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.xtext.Assignment; +import org.eclipse.xtext.Keyword; +import org.eclipse.xtext.RuleCall; +import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext; +import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor; + /** - * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#contentAssist on how to customize content assistant + * see + * http://www.eclipse.org/Xtext/documentation/latest/xtext.html#contentAssist on + * how to customize content assistant */ public class ConfigProposalProvider extends AbstractConfigProposalProvider { + @Override + public void completeImport_ImportURI(EObject model, Assignment assignment, + final ContentAssistContext context, + final ICompletionProposalAcceptor acceptor) { + final IPath rootPath = ResourcesPlugin.getWorkspace().getRoot() + .getFullPath(); + URI configURI = context.getRootModel().eResource().getURI(); + final IPath configPath = new Path(configURI.toPlatformString(false) + .replace(configURI.lastSegment(), "")); + IResourceProxyVisitor visitor = new IResourceProxyVisitor() { + + @Override + public boolean visit(IResourceProxy proxy) throws CoreException { + if (proxy.getType() != IResource.FILE) + return true; + + String name = proxy.getName(); + if (name.regionMatches(true, name.length() - 4, "room", 0, 4)) { + IPath relConfigPath = proxy.requestFullPath() + .makeRelativeTo(configPath); + IPath relWorkspacePath = proxy.requestFullPath() + .makeRelativeTo(rootPath); + String proposal = "\"" + relConfigPath.toString() + "\""; + String displayString = relConfigPath.lastSegment() + " - " + + relWorkspacePath; + acceptor.accept(createCompletionProposal(proposal, + new StyledString(displayString), null, context)); + } + return false; + } + }; + try { + ResourcesPlugin.getWorkspace().getRoot() + .accept(visitor, IResource.NONE); + } catch (CoreException e) { + e.printStackTrace(); + } + } + + @Override + public void completeActorInstanceConfig_Path(EObject model, + Assignment assignment, ContentAssistContext context, + ICompletionProposalAcceptor acceptor) { + super.completeActorInstanceConfig_Path(model, assignment, context, + acceptor); + + List<ActorRef> instances = collectInstances(((ActorInstanceConfig) model)); + for (ActorRef instance : instances) + acceptor.accept(createCompletionProposal(instance.getName(), + context)); + } + + @Override + public void completeRefPath_Refs(EObject model, Assignment assignment, + ContentAssistContext context, ICompletionProposalAcceptor acceptor) { + super.completeRefPath_Refs(model, assignment, context, acceptor); + + if (model instanceof ActorInstanceConfig) { + completeActorInstanceConfig_Path(model, assignment, context, + acceptor); + return; + } + + RefPath path = ((RefPath) model); + if (path.eContainer() instanceof ActorInstanceConfig) { + List<ActorRef> instances = collectInstances((ActorInstanceConfig) path + .eContainer()); + for (ActorRef instance : instances) + acceptor.accept(createCompletionProposal(instance.getName(), + context)); + } + } + + private List<ActorRef> collectInstances(ActorInstanceConfig config) { + List<ActorRef> refs = new ArrayList<ActorRef>(); + + ActorContainerClass root = config.getRoot(); + RefPath path = config.getPath(); + if (path != null) + root = ConfigUtil.resolve(root, path); + if (root != null) { + for (ActorContainerRef ref : RoomHelpers.getRefs(root, true)) { + if (ref instanceof ActorRef) + refs.add((ActorRef) ref); + } + } + + return refs; + } + + @Override + public void complete_STRING(EObject model, RuleCall ruleCall, + ContentAssistContext context, ICompletionProposalAcceptor acceptor) { + if (model instanceof AttrConfig) { + LiteralType type = ConfigUtil.getLiteralType(((AttrConfig) model) + .getAttribute()); + if (type != LiteralType.CHAR) + return; + } + + super.complete_STRING(model, ruleCall, context, acceptor); + } + + @Override + public void complete_IntLiteral(EObject model, RuleCall ruleCall, + ContentAssistContext context, ICompletionProposalAcceptor acceptor) { + if (model instanceof AttrConfig) { + LiteralType type = ConfigUtil.getLiteralType(((AttrConfig) model) + .getAttribute()); + if (type != LiteralType.INT && type != LiteralType.REAL) + return; + } + + acceptor.accept(createCompletionProposal("", "Integer", null, context)); + acceptor.accept(createCompletionProposal("", "Hexadecimal", null, + context)); + } + + @Override + public void complete_RealLiteral(EObject model, RuleCall ruleCall, + ContentAssistContext context, ICompletionProposalAcceptor acceptor) { + if (model instanceof AttrConfig) { + LiteralType type = ConfigUtil.getLiteralType(((AttrConfig) model) + .getAttribute()); + if (type != LiteralType.REAL) + return; + } + + acceptor.accept(createCompletionProposal("", "Real value", null, + context)); + } + + private static final String[] noneClassAttributes = new String[] {}; + private static final String[] noneInstanceAttributes = new String[] { + "min", "max" }; + + @Override + public void completeKeyword(Keyword keyword, + ContentAssistContext contentAssistContext, + ICompletionProposalAcceptor acceptor) { + + if (contentAssistContext.getCurrentModel() instanceof AttrConfig) { + AttrConfig config = (AttrConfig) contentAssistContext + .getCurrentModel(); + if (hideAttributeKeyword(config, keyword)) + return; + if (hideBooleanLiteralKeyword(config, keyword)) + return; + } + + super.completeKeyword(keyword, contentAssistContext, acceptor); + } + + private boolean hideBooleanLiteralKeyword(AttrConfig config, Keyword keyword) { + LiteralType type = ConfigUtil.getLiteralType(config.getAttribute()); + if (type != LiteralType.BOOL) + return true; + + return false; + } + + private boolean hideAttributeKeyword(AttrConfig config, Keyword keyword) { + String[] hideKeywords = new String[0]; + if (config.eContainer() instanceof ActorClassConfig) + hideKeywords = noneClassAttributes; + else if (config.eContainer() instanceof ActorInstanceConfig) + hideKeywords = noneInstanceAttributes; + + for (String s : hideKeywords) + if (s.equalsIgnoreCase(keyword.getValue())) + return true; + + return false; + } } diff --git a/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/labeling/ConfigDescriptionLabelProvider.java b/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/labeling/ConfigDescriptionLabelProvider.java index 3cdc1c622..a92b689f9 100644 --- a/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/labeling/ConfigDescriptionLabelProvider.java +++ b/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/labeling/ConfigDescriptionLabelProvider.java @@ -1,27 +1,27 @@ -/* -* generated by Xtext -*/ -package org.eclipse.etrice.core.ui.labeling; - -import org.eclipse.xtext.ui.label.DefaultDescriptionLabelProvider; - -/** - * Provides labels for a IEObjectDescriptions and IResourceDescriptions. - * - * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#labelProvider - */ -public class ConfigDescriptionLabelProvider extends DefaultDescriptionLabelProvider { - -/* - //Labels and icons can be computed like this: - - String text(IEObjectDescription ele) { - return "my "+ele.getName(); - } - - String image(IEObjectDescription ele) { - return ele.getEClass().getName() + ".gif"; - } -*/ - -} +/*
+* generated by Xtext
+*/
+package org.eclipse.etrice.core.ui.labeling;
+
+import org.eclipse.xtext.ui.label.DefaultDescriptionLabelProvider;
+
+/**
+ * Provides labels for a IEObjectDescriptions and IResourceDescriptions.
+ *
+ * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#labelProvider
+ */
+public class ConfigDescriptionLabelProvider extends DefaultDescriptionLabelProvider {
+
+/*
+ //Labels and icons can be computed like this:
+
+ String text(IEObjectDescription ele) {
+ return "my "+ele.getName();
+ }
+
+ String image(IEObjectDescription ele) {
+ return ele.getEClass().getName() + ".gif";
+ }
+*/
+
+}
diff --git a/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/labeling/ConfigLabelProvider.java b/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/labeling/ConfigLabelProvider.java index 05911c24d..c60be4f89 100644 --- a/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/labeling/ConfigLabelProvider.java +++ b/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/labeling/ConfigLabelProvider.java @@ -1,34 +1,34 @@ -/* -* generated by Xtext -*/ -package org.eclipse.etrice.core.ui.labeling; - -import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; -import org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider; - -import com.google.inject.Inject; - -/** - * Provides labels for a EObjects. - * - * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#labelProvider - */ -public class ConfigLabelProvider extends DefaultEObjectLabelProvider { - - @Inject - public ConfigLabelProvider(AdapterFactoryLabelProvider delegate) { - super(delegate); - } - -/* - //Labels and icons can be computed like this: - - String text(MyModel ele) { - return "my "+ele.getName(); - } - - String image(MyModel ele) { - return "MyModel.gif"; - } -*/ -} +/*
+* generated by Xtext
+*/
+package org.eclipse.etrice.core.ui.labeling;
+
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
+import org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider;
+
+import com.google.inject.Inject;
+
+/**
+ * Provides labels for a EObjects.
+ *
+ * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#labelProvider
+ */
+public class ConfigLabelProvider extends DefaultEObjectLabelProvider {
+
+ @Inject
+ public ConfigLabelProvider(AdapterFactoryLabelProvider delegate) {
+ super(delegate);
+ }
+
+/*
+ //Labels and icons can be computed like this:
+
+ String text(MyModel ele) {
+ return "my "+ele.getName();
+ }
+
+ String image(MyModel ele) {
+ return "MyModel.gif";
+ }
+*/
+}
diff --git a/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/outline/ConfigOutlineTreeProvider.java b/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/outline/ConfigOutlineTreeProvider.java index e653b972e..5498616f9 100644 --- a/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/outline/ConfigOutlineTreeProvider.java +++ b/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/outline/ConfigOutlineTreeProvider.java @@ -1,14 +1,14 @@ -/* -* generated by Xtext -*/ -package org.eclipse.etrice.core.ui.outline; - -import org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider; - -/** - * customization of the default outline structure - * - */ -public class ConfigOutlineTreeProvider extends DefaultOutlineTreeProvider { - -} +/*
+* generated by Xtext
+*/
+package org.eclipse.etrice.core.ui.outline;
+
+import org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider;
+
+/**
+ * customization of the default outline structure
+ *
+ */
+public class ConfigOutlineTreeProvider extends DefaultOutlineTreeProvider {
+
+}
diff --git a/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/quickfix/ConfigQuickfixProvider.java b/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/quickfix/ConfigQuickfixProvider.java index 3febfcd8b..28bfedce9 100644 --- a/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/quickfix/ConfigQuickfixProvider.java +++ b/plugins/org.eclipse.etrice.core.config.ui/src/org/eclipse/etrice/core/ui/quickfix/ConfigQuickfixProvider.java @@ -1,19 +1,19 @@ - -package org.eclipse.etrice.core.ui.quickfix; - -import org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider; - -public class ConfigQuickfixProvider extends DefaultQuickfixProvider { - -// @Fix(MyJavaValidator.INVALID_NAME) -// public void capitalizeName(final Issue issue, IssueResolutionAcceptor acceptor) { -// acceptor.accept(issue, "Capitalize name", "Capitalize the name.", "upcase.png", new IModification() { -// public void apply(IModificationContext context) throws BadLocationException { -// IXtextDocument xtextDocument = context.getXtextDocument(); -// String firstLetter = xtextDocument.get(issue.getOffset(), 1); -// xtextDocument.replace(issue.getOffset(), 1, firstLetter.toUpperCase()); -// } -// }); -// } - -} +
+package org.eclipse.etrice.core.ui.quickfix;
+
+import org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider;
+
+public class ConfigQuickfixProvider extends DefaultQuickfixProvider {
+
+// @Fix(MyJavaValidator.INVALID_NAME)
+// public void capitalizeName(final Issue issue, IssueResolutionAcceptor acceptor) {
+// acceptor.accept(issue, "Capitalize name", "Capitalize the name.", "upcase.png", new IModification() {
+// public void apply(IModificationContext context) throws BadLocationException {
+// IXtextDocument xtextDocument = context.getXtextDocument();
+// String firstLetter = xtextDocument.get(issue.getOffset(), 1);
+// xtextDocument.replace(issue.getOffset(), 1, firstLetter.toUpperCase());
+// }
+// });
+// }
+
+}
|