| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * 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: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| * |
| * This copyright notice shows up in the generated Java code |
| * |
| */ |
| |
| package org.eclipse.osbp.xtext.organizationdsl.ui.contentassist |
| |
| import java.util.HashMap |
| import javax.inject.Inject |
| import org.eclipse.emf.ecore.EObject |
| import org.eclipse.jface.viewers.StyledString |
| import org.eclipse.osbp.xtext.basic.ui.contentassist.BasicDSLProposalProviderHelper |
| import org.eclipse.osbp.xtext.datamartdsl.EventBrokerDataMart |
| import org.eclipse.osbp.xtext.datamartdsl.util.EventBrokerDatamartUtils |
| import org.eclipse.osbp.xtext.organizationdsl.Organization |
| import org.eclipse.osbp.xtext.organizationdsl.OrganizationPosition |
| import org.eclipse.osbp.xtext.organizationdsl.OrganizationSuperior |
| import org.eclipse.osbp.xtext.organizationdsl.ui.OrganizationDSLDocumentationTranslator |
| import org.eclipse.xtext.Assignment |
| import org.eclipse.xtext.Keyword |
| import org.eclipse.xtext.RuleCall |
| import org.eclipse.xtext.common.ui.contentassist.TerminalsProposalProvider |
| import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext |
| import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor |
| |
| /** |
| * see http://www.eclipse.org/Xtext/documentation.html#contentAssist on how to customize content assistant |
| */ |
| class OrganizationDslProposalProvider extends AbstractOrganizationDslProposalProvider { |
| @Inject TerminalsProposalProvider provider |
| @Inject BasicDSLProposalProviderHelper providerHelper |
| |
| override protected StyledString getKeywordDisplayString(Keyword keyword) { |
| return BasicDSLProposalProviderHelper.getKeywordDisplayString(keyword, |
| OrganizationDSLDocumentationTranslator.instance()) |
| } |
| |
| @Inject extension EventBrokerDatamartUtils |
| |
| /** |
| * This override will enable 1 length non letter characters as keyword. |
| */ |
| override protected boolean isKeywordWorthyToPropose(Keyword keyword) { |
| return true; |
| } |
| |
| override protected boolean isValidProposal(String proposal, String prefix, ContentAssistContext context) { |
| if ("T".equals(proposal)) { |
| return false; |
| } |
| var result = super.isValidProposal(proposal, prefix, context); |
| if (context.getCurrentModel() instanceof OrganizationSuperior) { |
| return true; |
| } else if (context.getCurrentModel() instanceof OrganizationPosition) { |
| if ("superiorPos=".equals(proposal)) { |
| return isSuperiorPosValidProposal(context.currentModel as OrganizationPosition, proposal, result); |
| } |
| return result; |
| } else if (context.getCurrentModel() instanceof Organization) { |
| if ("organization".equals(proposal)/* && (!(context.currentModel as Organization).isSubOrg) */) { |
| return isSubOrgValidProposal(context.currentModel as Organization, proposal, result); |
| } |
| return isDatamartValidProposal(context.currentModel as Organization, proposal, result); |
| } |
| return result; |
| } |
| |
| /** |
| * First organization position is not allowed to have a superior position (superiorPos) |
| */ |
| private def boolean isSuperiorPosValidProposal(OrganizationPosition position, String proposal, boolean result) { |
| if (position != null) { |
| var eObj = position.eContainer |
| while (!(eObj instanceof Organization)) { |
| eObj = eObj.eContainer |
| } |
| var org = (eObj as Organization) |
| val firstOrgPosition = org.organizationPositions.get(0) |
| if (firstOrgPosition != null && firstOrgPosition.name.equals(position.name)) { |
| return false |
| } |
| } |
| return result |
| } |
| |
| def boolean isSubOrgValidProposal(Organization organization, String proposal, boolean result) { |
| |
| // SubOrg only allowed if datamarts of the organization has more than 1 filter |
| // TODO (JCD): Have to be discussed under which conditions it could be reactivated. |
| // Temporary inactive |
| // if (organization != null) { |
| // var datamartsFilterMap = new HashMap<String, HashMap<String,String>>() |
| // for (CCEventBrokerDataMart dat : organization.datamarts) { |
| // datamartsFilterMap.put(dat.datamartDef.name, dat.filterMap) |
| // } |
| // return organization.enoughFiltersForSubOrg(datamartsFilterMap) |
| // } |
| return result |
| } |
| |
| def private boolean hasMoreThanXFilter(HashMap<String, HashMap<String, String>> datamartsFilterMap, int maxFilter) { |
| for (filterKey : datamartsFilterMap.keySet) { |
| if ((datamartsFilterMap.get(filterKey) as HashMap<String,String>).size > maxFilter) { |
| return true |
| } |
| } |
| return false |
| } |
| |
| def boolean isDatamartValidProposal(Organization organization, String proposal, boolean result) { |
| for (orgDataMart : organization.getDatamarts) { |
| if (orgDataMart.getDatamartDef != null) { |
| if (proposal.equals(orgDataMart.getDatamartDef.getName)) { |
| return false |
| } |
| } |
| } |
| return result |
| } |
| |
| def private HashMap<String, String> removeFilter(EventBrokerDataMart datamart, HashMap<String, String> filterIdMap) { |
| var eObj = datamart.eContainer() |
| |
| // as long as the root node is not reached |
| while (!(eObj instanceof Organization) || (eObj as Organization).superiorPosValue != null) { |
| eObj = eObj.eContainer() |
| } |
| if (eObj != null) { |
| for (EventBrokerDataMart dat : (eObj as Organization).datamarts) { |
| if (dat.getDatamartDef.name.equals(datamart.getDatamartDef.name)) { |
| |
| // remove the already default used filter of the root organization |
| var filterIdMapTemp = filterIdMap.clone as HashMap<String,String> |
| for (filter : filterIdMapTemp.keySet) { |
| if (dat.filter.equals(filter)) { |
| filterIdMap.remove(filterIdMapTemp.get(filter)); |
| } |
| } |
| } |
| } |
| } |
| return filterIdMap |
| } |
| |
| def private boolean enoughFiltersForSubOrg(Organization organization, |
| HashMap<String, HashMap<String, String>> datamartsFilterMap) { |
| if (organization != null && datamartsFilterMap.hasMoreThanXFilter(1)) { |
| if (organization.superiorPosValue != null) { |
| organization.datamarts.removeAlreadyUsedFilter(datamartsFilterMap) |
| var eObj = organization.eContainer() |
| |
| // as long as the root node of the superior organization is not reached |
| while (!(eObj instanceof Organization)) { |
| eObj = eObj.eContainer() |
| } |
| return (eObj as Organization).enoughFiltersForSubOrg(datamartsFilterMap) |
| } else { |
| return datamartsFilterMap.hasMoreThanXFilter(1) |
| } |
| } |
| return false |
| } |
| |
| def private boolean isSubOrg(EventBrokerDataMart datamart) { |
| |
| // Suborg-Check |
| var eObj = datamart.eContainer() |
| while (!(eObj instanceof Organization)) { |
| eObj = eObj.eContainer() |
| } |
| |
| // In case of a suborg |
| return isSubOrg(eObj as Organization) |
| } |
| |
| def private boolean isSubOrg(Organization organization) { |
| |
| // In case of a suborg |
| if (organization.superiorPosValue != null) { |
| return true |
| } |
| return false |
| } |
| |
| override completeOrganizationDataMart_Filter(EObject model, Assignment assignment, ContentAssistContext context, |
| ICompletionProposalAcceptor acceptor) { |
| var datamart = (context.currentModel as EventBrokerDataMart) |
| var filterIdMap = datamart.filterMap |
| if (datamart.isSubOrg) { |
| datamart.removeFilter(filterIdMap) |
| } |
| for (filter : filterIdMap.keySet) { |
| acceptor.accept( |
| createCompletionProposal("\"".concat(filterIdMap.get(filter)).concat("\""), filter.toString, null, |
| context)); |
| } |
| } |
| |
| override public void complete_QualifiedName(EObject model, RuleCall ruleCall, ContentAssistContext context, |
| ICompletionProposalAcceptor acceptor) { |
| providerHelper.complete_PackageName(model, ruleCall, context, acceptor, this) |
| } |
| |
| override public void complete_OrgQualifiedNameWithWildCard(EObject model, RuleCall ruleCall, |
| ContentAssistContext context, ICompletionProposalAcceptor acceptor) { |
| providerHelper.complete_PackageName(model, ruleCall, context, acceptor, this) |
| } |
| |
| // ------------------------ delegates to TerminalsProposalProvider ----------------- |
| override public void complete_TRANSLATABLESTRING(EObject model, RuleCall ruleCall, ContentAssistContext context, |
| ICompletionProposalAcceptor acceptor) { |
| provider.complete_STRING(model, ruleCall, context, acceptor) |
| } |
| |
| override public void complete_ID(EObject model, RuleCall ruleCall, ContentAssistContext context, |
| ICompletionProposalAcceptor acceptor) { |
| provider.complete_ID(model, ruleCall, context, acceptor) |
| } |
| |
| } |