List of usage examples for org.eclipse.jface.viewers TextCellEditor setValue
public final void setValue(Object value)
From source file:com.magicparser.gui.viewers.PartNameEditingSupport.java
License:Open Source License
@Override protected CellEditor getCellEditor(Object element) { if (element instanceof Part) { TextCellEditor cellEditor = new TextCellEditor((Composite) getViewer().getControl(), SWT.NONE); cellEditor.setValue(((Part<?, ?>) element).getName()); return cellEditor; }/*from ww w .j a v a2 s.co m*/ return null; }
From source file:com.magicparser.gui.viewers.PartValueReaderEditingSupport.java
License:Open Source License
@Override protected CellEditor getCellEditor(Object element) { if (element instanceof Part) { final PacketPartDescriptor descriptor = ((Part<?, ?>) element).getDescriptor(); TextCellEditor cellEditor = new TextCellEditor((Composite) getViewer().getControl(), SWT.NONE); cellEditor.setValue(((Part<?, ?>) element).getName()); return cellEditor; }// www .j ava 2s. c o m return null; }
From source file:com.nokia.sdt.uidesigner.ui.editparts.LayoutObjectLabelEditManager.java
License:Open Source License
protected void initCellEditor() { TextCellEditor editor = (TextCellEditor) getCellEditor(); LayoutObjectEditPart editPart = (LayoutObjectEditPart) getEditPart(); EObject object = (EObject) editPart.getModel(); getDirectEditRequest().setDirectEditFeature(propertyPath); if (initialKeyEvent == null) { Object value = ModelUtils.getEditablePropertyValueFromPath(object, propertyPath); editor.setValue(value); } else {//from ww w .j a va2 s .c o m Text text = (Text) editor.getControl(); /* @see DirectLabelEditManager.createCellEditorOn */ text.setText("" + initialKeyEvent.character); //$NON-NLS-1$ } Figure figure = (Figure) editPart.getFigure(); IEditPartEditorProvider editorProvider = (IEditPartEditorProvider) getEditPart(); ILookAndFeel lookAndFeel = editorProvider.getEditor().getDisplayModel().getLookAndFeel(); IFont ifont = directLabelEdit.getLabelFont(propertyPath, lookAndFeel); // get the scaling factor Dimension pointSize = new Dimension(100, 100); figure.translateToAbsolute(pointSize); double scale = pointSize.width / 100.; if (font != null) { font.dispose(); font = null; } // try to get the SWT version of the font used in the label float size; int scaledSize; if (ifont != null) { size = ifont.getSize(); scaledSize = (int) (size * scale); // make absolute size reasonable for display if (scaledSize < 10) { scaledSize = 10; size = (float) (scaledSize / scale); } else if (scaledSize > 96) { scaledSize = 96; size = (float) (scaledSize / scale); } font = ifont.getSWTFont(Display.getDefault(), scaledSize); } else { size = 12; scaledSize = (int) (size * scale); font = new Font(Display.getDefault(), "Arial Unicode MS", scaledSize, 0); //$NON-NLS-1$ } // need to make a GC for the display to get at the font metrics GC gc = new GC(Display.getDefault()); gc.setFont(font); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); // ensure the box is big enough to see text, but not too big String value = getCellEditor().getValue() != null ? getCellEditor().getValue().toString() : ""; //$NON-NLS-1$ // get enough width to add some text int minWidth = 128; if (value != null) minWidth = (int) (value.length() * (fontMetrics.getAverageCharWidth() + 5) / scale); if (minWidth >= 128) minWidth = (int) (128); // get enough height to actually show the font int minHeight = (int) Math.ceil(fontMetrics.getHeight() / scale); if (minHeight < 16) minHeight = 16; layoutObjectCellEditorLocator.setMinDimension(new Dimension(minWidth, minHeight)); Text text = (Text) editor.getControl(); text.setFont(font); hookCellEditor(); }
From source file:com.nokia.sdt.uidesigner.ui.editparts.NonLayoutObjectLabelEditManager.java
License:Open Source License
protected void initCellEditor() { TextCellEditor editor = (TextCellEditor) getCellEditor(); NonLayoutObjectEditPart editPart = (NonLayoutObjectEditPart) getEditPart(); getDirectEditRequest().setDirectEditFeature(dataModel.getNamePropertyId()); if (initialKeyEvent == null) { String initialLabelText = editPart.getComponentInstance().getName(); editor.setValue(initialLabelText); } else {//w w w . ja va2s. c o m editor.setValue("" + initialKeyEvent.character); //$NON-NLS-1$ } NonLayoutObjectFigure figure = (NonLayoutObjectFigure) editPart.getFigure(); font = figure.getFont(); Text text = (Text) editor.getControl(); /* @see DirectLabelEditManager.createCellEditorOn */ text.setFont(font); hookCellEditor(); }
From source file:org.eclipse.epf.authoring.gef.edit.FreeTextDirectEditManager.java
License:Open Source License
/** * @see org.eclipse.gef.tools.DirectEditManager#initCellEditor() *//* w ww .ja v a 2 s. c om*/ protected void initCellEditor() { TextCellEditor editor = (TextCellEditor) getCellEditor(); editor.setStyle(SWT.MULTI); Text t = (Text) editor.getControl(); verifyListener = new VerifyListener() { public void verifyText(VerifyEvent event) { Text text = (Text) getCellEditor().getControl(); String oldText = text.getText(); String leftText = oldText.substring(0, event.start); String rightText = oldText.substring(event.end, oldText.length()); GC gc = new GC(text); Point size = gc.textExtent(leftText + event.text + rightText); gc.dispose(); if (size.x != 0) size = text.computeSize(size.x, SWT.DEFAULT); getCellEditor().getControl().setSize(size.x, size.y); } }; t.addVerifyListener(verifyListener); String initialLabelText = ((NodeEditPart) this.getEditPart()).getDirectEditText(); editor.setValue(initialLabelText); Font f = figure.getFont(); FontMetrics fm = FigureUtilities.getFontMetrics(f); int h = fm.getHeight(); int w = fm.getAverageCharWidth(); t.setSize(initialLabelText.length() * w + 100, h + 50); if (f != null) t.setFont(f); else t.setFont(TemplateConstants.DEFAULT_FONT); t.selectAll(); }
From source file:org.eclipse.epf.authoring.gef.edit.TextFigureDirectEditManager.java
License:Open Source License
/** * @see org.eclipse.gef.tools.DirectEditManager#initCellEditor() *//*from ww w. j a v a2s .c o m*/ protected void initCellEditor() { TextCellEditor editor = (TextCellEditor) getCellEditor(); editor.setStyle(SWT.MULTI); Text t = (Text) editor.getControl(); verifyListener = new VerifyListener() { public void verifyText(VerifyEvent event) { Text text = (Text) getCellEditor().getControl(); String oldText = text.getText(); String leftText = oldText.substring(0, event.start); String rightText = oldText.substring(event.end, oldText.length()); GC gc = new GC(text); Point size = gc.textExtent(leftText + event.text + rightText); gc.dispose(); if (size.x != 0) size = text.computeSize(size.x, SWT.DEFAULT); getCellEditor().getControl().setSize(size.x, size.y); } }; t.addVerifyListener(verifyListener); String initialLabelText = ((NamedNodeEditPart) this.getEditPart()).getDirectEditText(); editor.setValue(initialLabelText); t.setFont(TemplateConstants.DEFAULT_FONT); t.selectAll(); }
From source file:org.locationtech.udig.catalog.service.database.ExtraParams.java
License:Open Source License
/** * Create a text based Extra param// ww w. jav a 2 s . com * * @param name name to display * @param param the actual param * @param defaultValue the default value to set if null then the text is blank */ public static ExtraParams text(String name, Param param, final String defaultValue) { return new ExtraParams(name, param) { @Override public CellEditor createCellEditor(Composite parent) { TextCellEditor textCellEditor = new TextCellEditor(parent); textCellEditor.setValue(defaultValue == null ? "" : defaultValue); return textCellEditor; } @Override public void setValue(String value) { getCellEditor().setValue(value.toString()); } @Override public String getValue() { return getCellEditor().getValue().toString(); } }; }
From source file:org.vast.stt.gui.widgets.OptionControl.java
License:Mozilla Public License
public TextCellEditor createTextCellEditor(String labelStr, String defText) { TextCellEditor tce = new TextCellEditor(this, SWT.RIGHT); tce.setValue(defText); Text text = (Text) tce.getControl(); GridData gd = new GridData(SWT.RIGHT, SWT.CENTER, false, false); gd.widthHint = 45;//ww w. j a va 2 s . com text.setLayoutData(gd); // Set limit to 7. Callers can override this setting by using the return Text object text.setTextLimit(7); // make bg gray to distinguish it from bg of parent text.setBackground(new Color(display, 210, 210, 210)); controlType = ControlType.TEXT; return tce; }