| /*=============================================================================# |
| # Copyright (c) 2019 Stephan Wahlbrink <sw@wahlbrink.eu> and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.internal.r.ui.editors; |
| |
| import org.eclipse.jface.text.contentassist.ICompletionProposalExtension6; |
| import org.eclipse.jface.viewers.StyledString; |
| import org.eclipse.swt.graphics.Image; |
| |
| import org.eclipse.statet.jcommons.collections.ImCollections; |
| import org.eclipse.statet.jcommons.collections.ImList; |
| import org.eclipse.statet.jcommons.lang.NonNullByDefault; |
| import org.eclipse.statet.jcommons.lang.Nullable; |
| |
| import org.eclipse.statet.r.core.RSymbolComparator; |
| import org.eclipse.statet.r.ui.RUI; |
| import org.eclipse.statet.r.ui.sourceediting.RAssistInvocationContext; |
| |
| |
| @NonNullByDefault |
| public class RHelpTopicCompletionProposal extends RSimpleCompletionProposal |
| implements ICompletionProposalExtension6 { |
| |
| |
| private ImList<String> pkgNames; |
| |
| |
| public RHelpTopicCompletionProposal(final ProposalParameters<RAssistInvocationContext> parameters, |
| final String replacementString, final @Nullable String pkgName) { |
| super(parameters, replacementString); |
| |
| this.pkgNames= (pkgName != null) ? ImCollections.newList(pkgName) : ImCollections.emptyList(); |
| } |
| |
| |
| public void addPackage(final String pkgName) { |
| this.pkgNames= ImCollections.addElementIfAbsent(this.pkgNames, pkgName, RSymbolComparator.R_NAMES_COLLATOR); |
| } |
| |
| |
| @Override |
| public StyledString computeStyledText() { |
| final StyledString styledText= new StyledString(getName()); |
| final ImList<String> pkgNames= this.pkgNames; |
| if (!pkgNames.isEmpty()) { |
| styledText.append(QUALIFIER_SEPARATOR, StyledString.QUALIFIER_STYLER); |
| styledText.append(pkgNames.get(0), StyledString.QUALIFIER_STYLER); |
| for (int i= 1; i < pkgNames.size(); i++) { |
| styledText.append(", ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ |
| styledText.append(pkgNames.get(i), StyledString.QUALIFIER_STYLER); |
| } |
| } |
| return styledText; |
| } |
| |
| @Override |
| public Image getImage() { |
| return RUI.getImage(RUI.IMG_OBJ_R_HELP_TOPIC); |
| } |
| |
| } |