Java源码示例:org.eclipse.jface.fieldassist.ContentProposalAdapter

示例1
private ContentProposalAdapter addContentAssistSimple(Text textControl) {
    char[] autoActivationCharacters = new char[] { '$', '{' };
    KeyStroke keyStroke = null;
    try {
        keyStroke = KeyStroke.getInstance("Ctrl+Space");
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // assume that myTextControl has already been created in some way
    List<Variable> variables = Variable.getVisibleVariables();
    String[] proposals = new String [variables.size()];
    for(int i=0;i<variables.size();i++) {
        proposals[i] = variables.get(i).getFullVariableName();
    }
    ContentProposalAdapter adapter = new ContentProposalAdapter(
            textControl , new TextContentAdapter(),
        new SimpleContentProposalProvider(proposals),
        keyStroke, autoActivationCharacters);
    adapter.setPropagateKeys(false);
    adapter.setFilterStyle(ContentProposalAdapter.FILTER_NONE);
    //adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    return adapter;
}
 
示例2
public void setProposalProvider(IContentProposalProvider proposalProvider) {
    final TextContentAdapter controlContentAdapter = new TextContentAdapter();
    proposalAdapter = new ContentProposalAdapter(getControl(), controlContentAdapter,
            proposalProvider, contentAssistKeyStroke, null);
    proposalAdapter.setPropagateKeys(true);
    proposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    proposalAdapter.setAutoActivationDelay(0);
    proposalAdapter.getControl().addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            AutoCompleteTextCellEditor.this.focusLost();
        }
    });
    proposalAdapter.addContentProposalListener(new IContentProposalListener() {

        @Override
        public void proposalAccepted(IContentProposal proposal) {
            fireApplyEditorValue();
        }

    });
}
 
示例3
public AutoCompletionField(final Control control, final IControlContentAdapter controlContentAdapter,
        final IExpressionProposalLabelProvider proposalLabelProvider) {

    contentProposalProvider = new ExpressionProposalProvider(proposalLabelProvider);
    contentProposalProvider.setFiltering(true);
    contentProposalAdapter = new BonitaContentProposalAdapter(control, controlContentAdapter, contentProposalProvider, null, null);
    contentProposalAdapter.setLabelProvider(new ExpressionLabelProvider() {

        @Override
        public String getText(final Object expression) {
            return ((ExpressionProposal) expression).getLabel();
        }
    });
    contentProposalAdapter.setPropagateKeys(true);
    contentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
}
 
示例4
public void manageNatureProviderAndAutocompletionProposal(final Object input) {
    if (input instanceof EObject && context == null) {
        setContext((EObject) input);
    }
    final Expression selectedExpression = getSelectedExpression();
    if (selectedExpression != null && ExpressionConstants.CONDITION_TYPE.equals(selectedExpression.getType())) {
        setProposalsFiltering(false);
        autoCompletion.getContentProposalAdapter().setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_INSERT);
    } else {
        autoCompletion.getContentProposalAdapter().setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    }
    autoCompletion.setContext(context);
    final Set<Expression> filteredExpressions = getFilteredExpressions();
    autoCompletion.setProposals(filteredExpressions.toArray(new Expression[filteredExpressions.size()]));

    final ArrayList<String> filteredExpressionType = getFilteredExpressionType();
    autoCompletion.setFilteredExpressionType(filteredExpressionType);
    if (filteredExpressionType.contains(ExpressionConstants.VARIABLE_TYPE)
            && filteredExpressionType.contains(ExpressionConstants.PARAMETER_TYPE)
            && filteredExpressionType.contains(ExpressionConstants.FORM_REFERENCE_TYPE)
            && filteredExpressions.isEmpty()) {
        contentAssistText.setProposalEnabled(false);
    } else {
        contentAssistText.setProposalEnabled(true);
    }
}
 
示例5
@Override
public void proposalAccepted(final IContentProposal proposal) {
    final int proposalAcceptanceStyle = autoCompletion.getContentProposalAdapter().getProposalAcceptanceStyle();
    if (proposalAcceptanceStyle == ContentProposalAdapter.PROPOSAL_REPLACE) {
        final Expression selectedExpression = getSelectedExpression();
        final CompoundCommand cc = new CompoundCommand("Update Expression (and potential side components)");
        final ExpressionProposal prop = (ExpressionProposal) proposal;
        final Expression copy = EcoreUtil.copy((Expression) prop.getExpression());
        copy.setReturnTypeFixed(selectedExpression.isReturnTypeFixed());
        sideModificationOnProposalAccepted(cc, copy);

        updateSelection(cc, copy);
        fireSelectionChanged(new SelectionChangedEvent(ExpressionViewer.this,
                new StructuredSelection(selectedExpression)));
        validate();
    }
}
 
示例6
public static <T> void addAutoCompleteSupport(Text text, IContentProposalProvider cpProvider,
	T defaultObject){
	setValue(text, defaultObject);
	
	ContentProposalAdapter cpAdapter =
		new ContentProposalAdapter(text, new TextContentAdapter(), cpProvider, null, null);
	cpAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
	cpAdapter.addContentProposalListener(new IContentProposalListener() {
		
		@Override
		public void proposalAccepted(IContentProposal proposal){
			text.setText(proposal.getLabel());
			text.setData(PROPOSAL_RET_OBJ, getProposalObject(proposal));
			text.setSelection(text.getText().length());
		}
	});
	text.addModifyListener(new ModifyListener() {
		
		@Override
		public void modifyText(ModifyEvent e){
			// resets the contents after manual change
			text.setData(PROPOSAL_RET_OBJ, null);
		}
	});
}
 
示例7
private void addContentProposal(Text text) {
	char[] autoActivationCharacters = null;// new char[] { '.' };
	KeyStroke keyStroke = null;
	try {
		keyStroke = KeyStroke.getInstance("Ctrl+Space");
	} catch (ParseException e) {
		e.printStackTrace();
	}
	adapter = new VersionContentProposalAdapter(text, new TextContentAdapter(),
			new VersionContentProposalProvider(), keyStroke, autoActivationCharacters);
	adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
	adapter.setPropagateKeys(true);
	adapter.setLabelProvider(VersionLabelProvider.getInstance());

}
 
示例8
protected void createContentAdpater() {
//		SemanticContentControlAdapter controlAdapter = new SemanticContentControlAdapter(proposalProvider, getViewer());
		adapter = new ContentProposalAdapter((Composite) getViewer().getControl(), proposalHandler.getProposalControlAdapter(), proposalHandler,
				keyStroke, null);
		adapter.setLabelProvider(proposalHandler.getProposalLabelProvider());
		adapter.setPropagateKeys(true);
		// TODO: If not set, the adapter uses the full width of the
		// GraphicalViewer as initial bounds
		adapter.setPopupSize(new Point(400, 150));
	}
 
示例9
private void installPatternContentAssist() {
  ContentProposalAdapter contentAssist = new ContentAssistCommandAdapter(
    patternText,
    new TextContentAdapter(),
    new FindReplaceDocumentAdapterContentProposalProvider( true ),
    CONTENT_ASSIST_PROPOSALS,
    new char[]{ '\\', '[', '(' },
    true );
  contentAssist.setEnabled( true );
}
 
示例10
private ContentProposalAdapter addContentAssistExtended(Text textControl) {
    char[] autoActivationCharacters = new char[] { '$', '{' };
    Map<String, String> proposals = new LinkedHashMap<String, String>();
    // add own variables
    proposals.putAll(Variable.getVariableInfoMap());
    // add eclipse variables
    proposals.putAll(Variable.getEclipseVariableInfoMap());
    ContentAssistCommandAdapter adapter = new ContentAssistCommandAdapter(textControl, new CommandVariableContentAdapter(),
            new CommandVariableContentProposalProvider(proposals), null,
            autoActivationCharacters, true);
    adapter.setPropagateKeys(false);
    adapter.setFilterStyle(ContentProposalAdapter.FILTER_NONE);
    return adapter;
}
 
示例11
private ContentProposalAdapter addContentAssist(Text textControl) {
    // add content assist to command text editor field
    if (useExtendedContentAssists) {
        return addContentAssistExtended(textControl);
    } else {
        return addContentAssistSimple(textControl);
    }
}
 
示例12
private ContentProposalAdapter addContentAssistExtended(Text textControl) {
    char[] autoActivationCharacters = new char[] { '$', '{' };
    Map<String, String> proposals = new LinkedHashMap<String, String>();
    // add internal variables
    proposals.putAll(Variable.getInternalVariableInfoMap());
    ContentAssistCommandAdapter adapter = new ContentAssistCommandAdapter(textControl, new CommandVariableContentAdapter(),
            new CommandVariableContentProposalProvider(proposals), null,
            autoActivationCharacters, true);
    adapter.setPropagateKeys(false);
    adapter.setFilterStyle(ContentProposalAdapter.FILTER_NONE);
    return adapter;
}
 
示例13
@Override
protected Control createDialogArea(Composite parent) {
	Composite area = (Composite) super.createDialogArea(parent);
	Composite container = new Composite(area, SWT.NONE);
	container.setLayoutData(new GridData(GridData.FILL_BOTH));
	GridLayout layout = new GridLayout(1, false);
	container.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
	container.setLayout(layout);
	Label enterClassNameLabel = new Label(container, SWT.NONE);
	enterClassNameLabel.setText("Enter Class Name: ");

	GridData dataClassName = new GridData();
	dataClassName.grabExcessHorizontalSpace = true;
	dataClassName.horizontalAlignment = GridData.FILL;

	inputText = new Text(container, SWT.BORDER);
	inputText.setLayoutData(dataClassName);

	ArrayList<PMClassFigure> classes = (ArrayList<PMClassFigure>) PackageMapDiagram.allClassFigures;
	String[] classNames= new String[classes.size()];
	for(int i=0; i< classes.size(); i++){
		PMClassFigure figure = classes.get(i);
		classNames[i] = figure.getName(); 

	}


	//new AutoCompleteField(inputText, new TextContentAdapter(),classNames);
	MyContentProposalProvider provider = new  MyContentProposalProvider(classNames);
	ContentProposalAdapter adapter = new ContentProposalAdapter(inputText, new TextContentAdapter(), provider, null, null);
	adapter.setPropagateKeys(true);
	adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);


	return area;
}
 
示例14
/**
 * @param control
 * @param contentAdapter
 * @param values
 */
public void installContentProposalAdapter( Control control,
		IControlContentAdapter contentAdapter, String[] values )
{
	IPreferenceStore store = getPreferenceStore( );
	boolean propagate = store.getBoolean( PreferenceConstants.PREF_CONTENTASSISTKEY_PROPAGATE );
	KeyStroke keyStroke = null;
	char[] autoActivationCharacters = null;
	int autoActivationDelay = store.getInt( PreferenceConstants.PREF_CONTENTASSISTDELAY );
	String triggerKey = getTriggerKey( );
	if ( triggerKey == null )
	{
		keyStroke = null;
	}
	else
	{
		keyStroke = getKeyStroke( triggerKey );
	}

	ContentProposalAdapter adapter = new ContentProposalAdapter( control,
			contentAdapter,
			getContentProposalProvider( values ),
			keyStroke,
			autoActivationCharacters );
	adapter.setAutoActivationDelay( autoActivationDelay );
	adapter.setPropagateKeys( propagate );
	adapter.setFilterStyle( getContentAssistFilterStyle( ) );
	adapter.setProposalAcceptanceStyle( getContentAssistAcceptance( ) );
}
 
示例15
private int getContentAssistAcceptance( )
{
	IPreferenceStore store = getPreferenceStore( );
	String acceptanceStyle = store.getString( PreferenceConstants.PREF_CONTENTASSISTRESULT );
	if ( acceptanceStyle.equals( PreferenceConstants.PREF_CONTENTASSISTRESULT_INSERT ) )
		return ContentProposalAdapter.PROPOSAL_INSERT;
	if ( acceptanceStyle.equals( PreferenceConstants.PREF_CONTENTASSISTRESULT_REPLACE ) )
		return ContentProposalAdapter.PROPOSAL_REPLACE;
	return ContentProposalAdapter.PROPOSAL_IGNORE;
}
 
示例16
private int getContentAssistFilterStyle( )
{
	IPreferenceStore store = getPreferenceStore( );
	String acceptanceStyle = store.getString( PreferenceConstants.PREF_CONTENTASSISTFILTER );
	if ( acceptanceStyle.equals( PreferenceConstants.PREF_CONTENTASSISTFILTER_CHAR ) )
		return ContentProposalAdapter.FILTER_CHARACTER;
	if ( acceptanceStyle.equals( PreferenceConstants.PREF_CONTENTASSISTFILTER_CUMULATIVE ) )
		return ContentProposalAdapter.FILTER_CUMULATIVE;
	return ContentProposalAdapter.FILTER_NONE;
}
 
示例17
private void updateAutoCompletionContentProposalAdapter() {
    if (ExpressionConstants.CONDITION_TYPE.equals(getSelectedExpression().getType())) {
        autoCompletion.getContentProposalAdapter().setEnabled(false);
        autoCompletion.getContentProposalAdapter().setProposalAcceptanceStyle(
                ContentProposalAdapter.PROPOSAL_INSERT);
    } else {
        autoCompletion.getContentProposalAdapter().setEnabled(true);
        autoCompletion.getContentProposalAdapter().setProposalAcceptanceStyle(
                ContentProposalAdapter.PROPOSAL_REPLACE);
    }
}
 
示例18
public static ContentProposalAdapter on(Text text, Supplier<List<Parameter>> locals) {
	ContentProposalAdapter adapter = new ContentProposalAdapter(
			text, new TextContentAdapter(),
			new ParameterProposals(locals),
			null, null);
	return adapter;
}
 
示例19
private void setupContentProposal(WorkspaceWizardPageForm wizardForm) {
	// Get the active binding's content assist key strokes
	KeyStroke keyInitiator = getActiveContentAssistBinding();

	// If unbound don't configure the content proposal
	if (null == keyInitiator) {
		return;
	}

	// Setup project content proposal
	ContentProposalAdapter projectAdapter = new ContentProposalAdapter(wizardForm.getProjectText(),
			new TextContentAdapter(), projectContentProposalProvider,
			keyInitiator, null);
	projectAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

	ImageDescriptor projectSymbol = PlatformUI.getWorkbench().getSharedImages()
			.getImageDescriptor(IDE.SharedImages.IMG_OBJ_PROJECT);
	projectAdapter.setLabelProvider(
			new SimpleImageContentProposalLabelProvider(projectSymbol));

	createContentProposalDecoration(wizardForm.getProjectText());

	sourceFolderContentProposalAdapter = new ContentProposalAdapter(
			wizardForm.getSourceFolderText(),
			new TextContentAdapter(), null,
			keyInitiator, null);
	sourceFolderContentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

	sourceFolderContentProposalAdapter.setLabelProvider(
			new SimpleImageContentProposalLabelProvider(
					ImageDescriptorCache.ImageRef.SRC_FOLDER.asImageDescriptor().orNull()));

	createContentProposalDecoration(wizardForm.getSourceFolderText());

	moduleSpecifierContentProposalAdapter = new ContentProposalAdapter(
			wizardForm.getModuleSpecifierText().getInternalText(),
			new TextContentAdapter(), null,
			keyInitiator, null);

	wizardForm.getModuleSpecifierText().createDecoration(contentProposalDecorationImage);

	// Update proposal context whenever the model changes
	model.addPropertyChangeListener(evt -> {
		if (evt.getPropertyName() == WorkspaceWizardModel.PROJECT_PROPERTY ||
				evt.getPropertyName() == WorkspaceWizardModel.SOURCE_FOLDER_PROPERTY) {
			updateProposalContext();
		}
	});
	updateProposalContext();

	moduleSpecifierContentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
	moduleSpecifierContentProposalAdapter
			.setLabelProvider(new ModuleSpecifierProposalLabelProvider());
}
 
示例20
public ContentProposalAdapter getContentProposalAdapter() {
   return contentProposalAdapter;
}
 
示例21
public CodingSelectionComposite(Composite parent, int style){
	super(parent, style);
	GridLayout gridLayout = new GridLayout(2, false);
	gridLayout.marginHeight = 0;
	gridLayout.marginWidth = 0;
	setLayout(gridLayout);
	
	systemCombo = new ComboViewer(this);
	systemCombo.setContentProvider(new ArrayContentProvider());
	systemCombo.setLabelProvider(new LabelProvider() {
		@Override
		public String getText(Object element){
			return super.getText(element);
		}
	});
	systemCombo.setInput(CodingServiceComponent.getService().getAvailableCodeSystems().stream()
		.filter(system -> !system.equals(CodingSystem.ELEXIS_LOCAL_CODESYSTEM.getSystem()))
		.collect(Collectors.toList()));
	systemCombo.addSelectionChangedListener(new ISelectionChangedListener() {
		@Override
		public void selectionChanged(SelectionChangedEvent event){
			if (proposalProvider != null) {
				ISelection selection = event.getSelection();
				if (selection instanceof StructuredSelection && !selection.isEmpty()) {
					proposalProvider
						.setSelectedSystem(Optional
							.of((String) ((StructuredSelection) selection).getFirstElement()));
				} else {
					proposalProvider.setSelectedSystem(Optional.empty());
				}
			}
		}
	});
	
	selectionTxt = new Text(this, SWT.BORDER);
	selectionTxt.setMessage("Coding selektieren");
	selectionTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
	proposalProvider = new CodingContentProposalProvider();
	ContentProposalAdapter toAddressProposalAdapter = new ContentProposalAdapter(selectionTxt,
		new TextContentAdapter(), proposalProvider, null, null);
	toAddressProposalAdapter.addContentProposalListener(new IContentProposalListener() {
		@Override
		public void proposalAccepted(IContentProposal proposal){
			selectionTxt.setText(proposal.getContent());
			proposalProvider.getCodingForProposal(proposal)
				.ifPresent(iCoding -> selectedCode = Optional.of(iCoding));
			selectionTxt.setSelection(selectionTxt.getText().length());
			Object[] listeners = selectionListeners.getListeners();
			for (Object object : listeners) {
				SelectionChangedEvent selectionEvent =
					new SelectionChangedEvent(CodingSelectionComposite.this, getSelection());
				((ISelectionChangedListener) object).selectionChanged(selectionEvent);
			}
		}
	});
	MenuManager menuManager = new MenuManager();
	menuManager.add(new Action("Lokalen Code anlegen") {
		@Override
		public void run(){
			TransientCoding transientCoding = new TransientCoding(
				CodingSystem.ELEXIS_LOCAL_CODESYSTEM.getSystem(),
				selectionTxt.getSelectionText(),
				"");
			CodingEditDialog editDialog = new CodingEditDialog(transientCoding, getShell());
			if (editDialog.open() == CodingEditDialog.OK) {
				CodingServiceComponent.getService().addLocalCoding(transientCoding);
				// trigger reload of code system
				setCodeSystem(CodingSystem.ELEXIS_LOCAL_CODESYSTEM.getSystem());
			}
		}
		
		@Override
		public boolean isEnabled(){
			ISelection systemSelection = systemCombo.getSelection();
			if (systemSelection instanceof StructuredSelection) {
				Object codeSystem = ((StructuredSelection) systemSelection).getFirstElement();
				if(codeSystem instanceof String && codeSystem.equals(CodingSystem.ELEXIS_LOCAL_CODESYSTEM.getSystem()) ) {
					String text = selectionTxt.getSelectionText();
					return text != null && !text.isEmpty();
				}
			}
			return false;
		}
	});
	menuManager.addMenuListener(new IMenuListener() {
		@Override
		public void menuAboutToShow(IMenuManager manager){
			IContributionItem[] items = manager.getItems();
			for (IContributionItem iContributionItem : items) {
				iContributionItem.update();
			}
		}
	});
	selectionTxt.setMenu(menuManager.createContextMenu(selectionTxt));
}
 
示例22
public static ContentProposalAdapter on(Text text) {
	return on(text, null);
}