| /** |
| * Copyright (c) 2011, 2018 - 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 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| * generated by Xtext 2.11.0 |
| */ |
| package org.eclipse.osbp.xtext.signal.ui.contentassist; |
| |
| import com.google.inject.Inject; |
| import java.net.MalformedURLException; |
| import java.net.URL; |
| import java.nio.file.Paths; |
| import org.eclipse.emf.common.util.EList; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.jface.text.contentassist.ICompletionProposal; |
| import org.eclipse.jface.viewers.StyledString; |
| import org.eclipse.osbp.xtext.basic.ui.contentassist.BasicDSLProposalProviderHelper; |
| import org.eclipse.osbp.xtext.signal.SignalDatainterchange; |
| import org.eclipse.osbp.xtext.signal.SignalExecutionTypeEnum; |
| import org.eclipse.osbp.xtext.signal.SignalScheduler; |
| import org.eclipse.osbp.xtext.signal.SignalWatcher; |
| import org.eclipse.osbp.xtext.signal.WatcherDefinition; |
| import org.eclipse.osbp.xtext.signal.WatcherWithFileMask; |
| import org.eclipse.osbp.xtext.signal.WatcherWithFileName; |
| import org.eclipse.osbp.xtext.signal.ui.SignalDSLDocumentationTranslator; |
| import org.eclipse.osbp.xtext.signal.ui.contentassist.AbstractSignalDSLProposalProvider; |
| import org.eclipse.osbp.xtext.signal.ui.contentassist.DirectoryNameTextApplier; |
| 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.ConfigurableCompletionProposal; |
| import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext; |
| import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor; |
| import org.eclipse.xtext.xbase.lib.Exceptions; |
| |
| @SuppressWarnings("all") |
| public class SignalDSLProposalProvider extends AbstractSignalDSLProposalProvider { |
| @Inject |
| private TerminalsProposalProvider provider; |
| |
| @Inject |
| private BasicDSLProposalProviderHelper providerHelper; |
| |
| @Override |
| protected StyledString getKeywordDisplayString(final Keyword keyword) { |
| return BasicDSLProposalProviderHelper.getKeywordDisplayString(keyword, |
| SignalDSLDocumentationTranslator.instance()); |
| } |
| |
| /** |
| * This override will enable 1 length non letter characters as keyword. |
| */ |
| @Override |
| protected boolean isKeywordWorthyToPropose(final Keyword keyword) { |
| return true; |
| } |
| |
| @Override |
| public void complete_QualifiedName(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| this.providerHelper.complete_PackageName(model, ruleCall, context, acceptor, this); |
| } |
| |
| public void directoryPickerProposal(final EObject model, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| ICompletionProposal _createCompletionProposal = this.createCompletionProposal("Select directory...", context); |
| ConfigurableCompletionProposal dirName = ((ConfigurableCompletionProposal) _createCompletionProposal); |
| if ((dirName != null)) { |
| DirectoryNameTextApplier applier = new DirectoryNameTextApplier(); |
| applier.setContext(context); |
| dirName.setTextApplier(applier); |
| } |
| acceptor.accept(dirName); |
| } |
| |
| /** |
| * This method decided which proposals will be valid. |
| */ |
| @Override |
| protected boolean isValidProposal(final String proposal, final String prefix, final ContentAssistContext context) { |
| boolean result = super.isValidProposal(proposal, prefix, context); |
| EObject _currentModel = context.getCurrentModel(); |
| if ((_currentModel instanceof SignalWatcher)) { |
| EObject _currentModel_1 = context.getCurrentModel(); |
| result = this.isValidProposalForSignalWatcherType(proposal, prefix, ((SignalWatcher) _currentModel_1), result); |
| } else { |
| EObject _currentModel_2 = context.getCurrentModel(); |
| if ((_currentModel_2 instanceof SignalDatainterchange)) { |
| EObject _currentModel_3 = context.getCurrentModel(); |
| result = this.isValidProposalSignalDatainterchange(proposal, prefix, ((SignalDatainterchange) _currentModel_3), result); |
| } |
| } |
| return result; |
| } |
| |
| public boolean isValidProposalSignalDatainterchange(final String proposal, final String prefix, final SignalDatainterchange interchange, final boolean result) { |
| if ((proposal.equals("applyon") && (interchange != null))) { |
| EObject _eContainer = interchange.eContainer(); |
| if ((_eContainer instanceof WatcherWithFileMask)) { |
| return false; |
| } else { |
| EObject _eContainer_1 = interchange.eContainer(); |
| if ((_eContainer_1 instanceof WatcherWithFileName)) { |
| EObject _eContainer_2 = interchange.eContainer(); |
| WatcherWithFileName watcher = ((WatcherWithFileName) _eContainer_2); |
| int _size = watcher.getInterchanges().size(); |
| boolean _greaterThan = (_size > 1); |
| if (_greaterThan) { |
| boolean _basedInterchangeDefined = this.basedInterchangeDefined(watcher.getInterchanges()); |
| if (_basedInterchangeDefined) { |
| return false; |
| } |
| } |
| } else { |
| EObject _eContainer_3 = interchange.eContainer(); |
| if ((_eContainer_3 instanceof SignalScheduler)) { |
| return false; |
| } |
| } |
| } |
| } |
| return result; |
| } |
| |
| private boolean isValidProposalForSignalWatcherType(final String proposal, final String prefix, final SignalWatcher signal, final boolean result) { |
| WatcherDefinition watcher = signal.getDefinition(); |
| if ((watcher != null)) { |
| if ((watcher instanceof WatcherWithFileMask)) { |
| boolean _equals = proposal.equals("applyon"); |
| if (_equals) { |
| return false; |
| } |
| } else { |
| if ((watcher instanceof WatcherWithFileName)) { |
| if (((((WatcherWithFileName)watcher).getInterchanges().size() < 1) && (proposal.equals(SignalExecutionTypeEnum.NOSEQ.getLiteral()) || proposal.equals(SignalExecutionTypeEnum.SEQ.getLiteral())))) { |
| return false; |
| } |
| } |
| } |
| } |
| return result; |
| } |
| |
| public boolean basedInterchangeDefined(final EList<SignalDatainterchange> interchanges) { |
| for (final SignalDatainterchange unit : interchanges) { |
| boolean _isBaseinterchange = unit.isBaseinterchange(); |
| if (_isBaseinterchange) { |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| public URL getDirectoryURL(final String directory) { |
| try { |
| return new URL(directory); |
| } catch (final Throwable _t) { |
| if (_t instanceof MalformedURLException) { |
| final MalformedURLException e1 = (MalformedURLException)_t; |
| if ((e1.getMessage().startsWith("unknown protocol") || e1.getMessage().startsWith("no protocol"))) { |
| try { |
| return Paths.get(directory).toUri().toURL(); |
| } catch (final Throwable _t_1) { |
| if (_t_1 instanceof MalformedURLException) { |
| final MalformedURLException e2 = (MalformedURLException)_t_1; |
| return null; |
| } else { |
| throw Exceptions.sneakyThrow(_t_1); |
| } |
| } |
| } |
| } else { |
| throw Exceptions.sneakyThrow(_t); |
| } |
| } |
| return null; |
| } |
| |
| @Override |
| public void complete_INT(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| this.provider.complete_INT(model, ruleCall, context, acceptor); |
| } |
| |
| @Override |
| public void complete_TRANSLATABLEID(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| this.provider.complete_ID(model, ruleCall, context, acceptor); |
| } |
| |
| @Override |
| public void complete_TRANSLATABLESTRING(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| this.provider.complete_STRING(model, ruleCall, context, acceptor); |
| } |
| |
| @Override |
| public void complete_STRING(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| this.provider.complete_STRING(model, ruleCall, context, acceptor); |
| } |
| } |