| /** |
| * 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 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 |
| * |
| * |
| * This copyright notice shows up in the generated Java code |
| */ |
| package org.eclipse.osbp.xtext.topologydsl.ui.contentassist; |
| |
| import java.io.File; |
| import java.io.FileFilter; |
| import javax.inject.Inject; |
| import org.eclipse.core.internal.resources.Workspace; |
| import org.eclipse.core.resources.IContainer; |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.resources.IWorkspace; |
| import org.eclipse.core.resources.ResourcesPlugin; |
| import org.eclipse.emf.common.util.URI; |
| 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.topologydsl.ui.TopologyDSLDocumentationTranslator; |
| import org.eclipse.osbp.xtext.topologydsl.ui.contentassist.AbstractTopologyDSLProposalProvider; |
| import org.eclipse.xtend2.lib.StringConcatenation; |
| 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.ConfigurableCompletionProposal; |
| import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext; |
| import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor; |
| |
| @SuppressWarnings("all") |
| public class TopologyDSLProposalProvider extends AbstractTopologyDSLProposalProvider { |
| @Inject |
| private TerminalsProposalProvider provider; |
| |
| @Inject |
| private BasicDSLProposalProviderHelper providerHelper; |
| |
| public void filePickerProposal(final EObject model, final Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor, final String fileExtension) { |
| URI uri = context.getResource().getURI(); |
| if (((uri != null) && uri.isPlatform())) { |
| String projectName = ""; |
| String[] _segments = uri.segments(); |
| for (final String segment : _segments) { |
| boolean _contains = segment.contains("model.topology"); |
| if (_contains) { |
| projectName = segment; |
| } |
| } |
| boolean _isEmpty = projectName.isEmpty(); |
| boolean _not = (!_isEmpty); |
| if (_not) { |
| IWorkspace _workspace = ResourcesPlugin.getWorkspace(); |
| Workspace workspace = ((Workspace) _workspace); |
| IProject[] projects = workspace.getRoot().getProjects(IContainer.INCLUDE_HIDDEN); |
| for (final IProject project : projects) { |
| boolean _exists = project.exists(); |
| if (_exists) { |
| String[] _segments_1 = project.getFullPath().segments(); |
| for (final String segment_1 : _segments_1) { |
| if (((segment_1 != null) && segment_1.contains(projectName))) { |
| java.net.URI projectLocation = workspace.getFileSystemManager().locationURIFor(project, true); |
| if ((projectLocation != null)) { |
| File projectDir = new File(projectLocation); |
| File[] _listFiles = projectDir.listFiles(); |
| for (final File projectFile : _listFiles) { |
| boolean _endsWith = projectFile.getName().endsWith("topologies"); |
| if (_endsWith) { |
| File topologiesDir = projectFile; |
| boolean _isDirectory = topologiesDir.isDirectory(); |
| if (_isDirectory) { |
| final FileFilter _function = (File path) -> { |
| return path.getName().endsWith(fileExtension); |
| }; |
| File[] _listFiles_1 = topologiesDir.listFiles(_function); |
| for (final File file : _listFiles_1) { |
| { |
| final String fileNameR = file.getName().replace(fileExtension, ""); |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("\""); |
| _builder.append(fileNameR); |
| _builder.append("\""); |
| ICompletionProposal _createCompletionProposal = this.createCompletionProposal(_builder.toString(), context); |
| final ConfigurableCompletionProposal fileNameProposal = ((ConfigurableCompletionProposal) _createCompletionProposal); |
| acceptor.accept(fileNameProposal); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| @Override |
| public void completeTopology_FileName(final EObject model, final Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| this.filePickerProposal(model, assignment, context, acceptor, ".json"); |
| } |
| |
| @Override |
| protected StyledString getKeywordDisplayString(final Keyword keyword) { |
| return BasicDSLProposalProviderHelper.getKeywordDisplayString(keyword, |
| TopologyDSLDocumentationTranslator.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); |
| } |
| |
| @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_ID(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { |
| this.provider.complete_ID(model, ruleCall, context, acceptor); |
| } |
| } |