org.eclipse.jface.fieldassist.TextContentAdapter Java Examples

The following examples show how to use org.eclipse.jface.fieldassist.TextContentAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TexlipseProjectPropertyPage.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create a text field for language setting.
 * @param parent parent component
 */
private void addLangSection(Composite parent) {
    
    Label descr = new Label(parent, SWT.LEFT | SWT.WRAP);
    descr.setLayoutData(new GridData());
    descr.setText(TexlipsePlugin.getResourceString("propertiesLanguageDescription"));
    
    Composite composite = createDefaultComposite(parent, 2);
    
    Label label = new Label(composite, SWT.LEFT);
    label.setLayoutData(new GridData());
    label.setText(TexlipsePlugin.getResourceString("propertiesLanguage"));
    
    languageField = new Text(composite, SWT.SINGLE | SWT.BORDER);
    languageField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    languageField.setTextLimit(2);
    new AutoCompleteField(languageField, new TextContentAdapter(), Locale.getISOLanguages());
}
 
Example #2
Source File: CommandDataDialog.java    From EasyShell with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: AutoCompleteTextCellEditor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
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();
        }

    });
}
 
Example #4
Source File: AutoCompleteTextUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
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);
		}
	});
}
 
Example #5
Source File: NpmInstallWidget.java    From typescript.java with MIT License 5 votes vote down vote up
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());

}
 
Example #6
Source File: DynamicWorkingSetPage.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
private void installPatternContentAssist() {
  ContentProposalAdapter contentAssist = new ContentAssistCommandAdapter(
    patternText,
    new TextContentAdapter(),
    new FindReplaceDocumentAdapterContentProposalProvider( true ),
    CONTENT_ASSIST_PROPOSALS,
    new char[]{ '\\', '[', '(' },
    true );
  contentAssist.setEnabled( true );
}
 
Example #7
Source File: SearchDialog.java    From JDeodorant with MIT License 5 votes vote down vote up
@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;
}
 
Example #8
Source File: ParameterProposals.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
public static ContentProposalAdapter on(Text text, Supplier<List<Parameter>> locals) {
	ContentProposalAdapter adapter = new ContentProposalAdapter(
			text, new TextContentAdapter(),
			new ParameterProposals(locals),
			null, null);
	return adapter;
}
 
Example #9
Source File: WorkspaceWizardPage.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
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());
}
 
Example #10
Source File: CodingSelectionComposite.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
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));
}