List of usage examples for org.eclipse.jface.dialogs Dialog convertHeightInCharsToPixels
public static int convertHeightInCharsToPixels(FontMetrics fontMetrics, int chars)
From source file:org.jboss.tools.runtime.ui.internal.dialogs.RuntimeCheckboxTreeViewer.java
License:Open Source License
public RuntimeCheckboxTreeViewer(Composite parent, final RuntimePath[] runtimePaths2, int heightHint) { super(parent, SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE); GridData gd;//from w w w.java 2 s . co m Tree tree = getTree(); gd = new GridData(SWT.FILL, SWT.FILL, true, true); GC gc = new GC(parent); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); gd.minimumHeight = Dialog.convertHeightInCharsToPixels(fontMetrics, heightHint); tree.setLayoutData(gd); tree.setHeaderVisible(true); tree.setLinesVisible(true); String[] columnNames = new String[] { Messages.RuntimeCheckboxTreeViewer_Name, Messages.RuntimeCheckboxTreeViewer_Type, Messages.RuntimeCheckboxTreeViewer_Version, Messages.RuntimeCheckboxTreeViewer_Errors, Messages.RuntimeCheckboxTreeViewer_Location }; int[] columnWidths = new int[] { 200, 70, 60, 150, 150 }; for (int i = 0; i < columnNames.length; i++) { TreeViewerColumn tc = new TreeViewerColumn(this, SWT.NONE); tc.getColumn().setText(columnNames[i]); tc.getColumn().setWidth(columnWidths[i]); } setLabelProvider(new RuntimeLabelProvider()); List<RuntimeDefinition> runtimeDefinitions = new ArrayList<RuntimeDefinition>(); for (RuntimePath runtimePath : runtimePaths2) { runtimeDefinitions.addAll(Arrays.asList(runtimePath.getRuntimeDefinitions())); } setContentProvider(new RuntimeContentProvider(runtimeDefinitions)); setInput(runtimeDefinitions); for (RuntimeDefinition definition : runtimeDefinitions) { setChecked(definition, definition.isEnabled()); } addContentAssist(); }
From source file:org.jboss.tools.windup.ui.internal.rules.delegate.JavaEmbeddedEditor.java
License:Open Source License
public Control createControls(Composite parent) { fViewer = new JDISourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.LEFT_TO_RIGHT); fViewer.setEditable(false);//from www .j a va2s . co m ControlDecoration decoration = new ControlDecoration(fViewer.getControl(), SWT.TOP | SWT.LEFT); decoration.setShowOnlyOnFocus(true); FieldDecoration dec = FieldDecorationRegistry.getDefault() .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL); decoration.setImage(dec.getImage()); decoration.setDescriptionText(dec.getDescription()); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); // set height/width hints based on font GC gc = new GC(fViewer.getTextWidget()); gc.setFont(fViewer.getTextWidget().getFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gd.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 17); gd.widthHint = Dialog.convertWidthInCharsToPixels(fontMetrics, 40); gc.dispose(); fViewer.getControl().setLayoutData(gd); fContentAssistHandler = new AbstractHandler() { @Override public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException { fViewer.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); return null; } }; fUndoHandler = new AbstractHandler() { @Override public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException { fViewer.doOperation(ITextOperationTarget.UNDO); return null; } }; fRedoHandler = new AbstractHandler() { @Override public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException { fViewer.doOperation(ITextOperationTarget.REDO); return null; } }; fHandlerService = PlatformUI.getWorkbench().getAdapter(IHandlerService.class); fViewer.getControl().addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { activateHandlers(); } @Override public void focusLost(FocusEvent e) { deactivateHandlers(); } }); parent.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { dispose(); } }); fViewer.getTextWidget().addVerifyKeyListener(new VerifyKeyListener() { @Override public void verifyKey(VerifyEvent event) { fViewer.getTextWidget().getText(); } }); return parent; }
From source file:org.metaborg.spoofax.eclipse.util.ui.FilteringInfoPopup.java
License:Open Source License
protected Text createFilterText(Composite parent) { filterText = new Text(parent, SWT.NONE); GridData data = new GridData(GridData.FILL_HORIZONTAL); GC gc = new GC(parent); gc.setFont(parent.getFont());//from ww w .j a v a2 s. c o m FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 1); data.horizontalAlignment = GridData.FILL; data.verticalAlignment = GridData.CENTER; filterText.setLayoutData(data); filterText.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (e.keyCode == 0x0D) { // return Object selectedElement = getSelectedElement(); close(); handleElementSelected(selectedElement); } if (e.keyCode == SWT.ARROW_DOWN) treeViewer.getTree().setFocus(); if (e.keyCode == SWT.ARROW_UP) treeViewer.getTree().setFocus(); if (e.character == 0x1B) // ESC dispose(); } public void keyReleased(KeyEvent e) { // do nothing } }); return filterText; }
From source file:org.springframework.ide.eclipse.roo.ui.internal.RooInplaceDialog.java
License:Open Source License
private Text createFilterText(Composite parent) { label = new Label(parent, SWT.NONE); label.setText("roo> "); filterText = new Text(parent, SWT.NONE); GridData data = new GridData(GridData.FILL_HORIZONTAL); GC gc = new GC(parent); gc.setFont(parent.getFont());/*from www .j a va2s .co m*/ FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 1); data.horizontalAlignment = GridData.FILL; data.verticalAlignment = GridData.CENTER; filterText.setLayoutData(data); this.tab.addTypeFieldAssistToText(this.filterText); filterText.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (e.character == 0x1B) { // ESC dispose(); return; } isDeactivateListenerActive = false; // otherwise dialog will be disposed when popup opens tab.processKeyEvent(tab.getText(), e, filterText.getText()); isDeactivateListenerActive = true; if (e.doit && e.keyCode == 0x0D) { // return dispose(); return; } } public void keyReleased(KeyEvent e) { // do nothing } }); return filterText; }
From source file:org.springsource.ide.eclipse.gradle.ui.cli.inplace.ConsoleInplaceDialog.java
License:Open Source License
private TasksViewer createCommandText(Composite parent) { promptLabel = new Label(parent, SWT.NONE); promptLabel.setText("Tasks:"); GridData data = new GridData(); data.verticalAlignment = GridData.CENTER; promptLabel.setLayoutData(data);//from w ww .java 2s . c om commandText = new TasksViewer(parent, index, true); commandText.setDocument(new Document()); FontData fontData = commandText.getSourceViewer().getTextWidget().getFont().getFontData()[0]; fontData.setStyle(SWT.BOLD); promptLabel.setFont(new Font(parent.getDisplay(), fontData)); data = new GridData(GridData.FILL_HORIZONTAL); GC gc = new GC(parent); gc.setFont(promptLabel.getFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 1); data.horizontalAlignment = GridData.FILL; data.verticalAlignment = GridData.CENTER; commandText.getSourceViewer().getControl().setLayoutData(data); commandText.getSourceViewer().appendVerifyKeyListener(new VerifyKeyListener() { @Override public void verifyKey(VerifyEvent e) { if (e.character == SWT.ESC) { // ESC dispose(); return; } if (e.doit && e.keyCode == 0x0D && isDeactivateListenerActive) { // return e.doit = false; IProject project = getSelectedProject(); if (!isValidProject(project)) { openInformationMessage("Invalid Project ", getStatusMessage()); } else { String taskStr = commandText.getSourceViewer().getDocument().get(); history.push(new CommandEntry(taskStr, project.getName())); final ILaunchConfiguration conf = GradleLaunchConfigurationDelegate .createDefault(GradleCore.create(project), taskStr, false); JobUtil.schedule(NO_RULE, new GradleRunnable(taskStr) { @Override public void doit(IProgressMonitor mon) throws Exception { conf.launch("run", mon, false, true); } }); commandText.getSourceViewer().getDocument().set(""); if (!isPinned()) dispose(); } return; } if (e.doit && e.keyCode == SWT.ARROW_DOWN || e.keyCode == SWT.ARROW_UP) { e.doit = false; showHistoryPopup(); return; } } }); commandText.getSourceViewer().getContentAssistantFacade().addCompletionListener(new ICompletionListener() { @Override public void assistSessionStarted(ContentAssistEvent event) { isDeactivateListenerActive = false; } @Override public void assistSessionEnded(ContentAssistEvent event) { isDeactivateListenerActive = true; dialogShell.setActive(); } @Override public void selectionChanged(ICompletionProposal proposal, boolean smartToggle) { // nothing } }); return commandText; }
From source file:org.summer.sdt.debug.ui.breakpoints.JavaBreakpointConditionEditor.java
License:Open Source License
/** * Creates the condition editor widgets and returns the top level * control.//from www . j a v a 2s .c om * * @param parent composite to embed the editor controls in * @return top level control */ @Override public Control createControl(Composite parent) { Composite controls = SWTFactory.createComposite(parent, parent.getFont(), 2, 1, GridData.FILL_HORIZONTAL, 0, 0); fConditional = SWTFactory.createCheckButton(controls, processMnemonics(PropertyPageMessages.JavaBreakpointConditionEditor_0), null, false, 1); fConditional.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); fConditional.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean checked = fConditional.getSelection(); setEnabled(checked, true); setDirty(PROP_CONDITION_ENABLED); } }); Composite radios = SWTFactory.createComposite(controls, controls.getFont(), 2, 1, GridData.FILL_HORIZONTAL, 0, 0); fWhenTrue = SWTFactory.createRadioButton(radios, processMnemonics(PropertyPageMessages.JavaBreakpointConditionEditor_1)); fWhenTrue.setLayoutData(new GridData()); fWhenChange = SWTFactory.createRadioButton(radios, processMnemonics(PropertyPageMessages.JavaBreakpointConditionEditor_2)); fWhenChange.setLayoutData(new GridData()); fWhenTrue.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { setDirty(PROP_CONDITION_SUSPEND_POLICY); } }); fWhenChange.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { setDirty(PROP_CONDITION_SUSPEND_POLICY); } }); if (fConditionHistoryDialogSettings != null) { fLocalConditionHistory = new HashMap<IJavaLineBreakpoint, Stack<String>>(); fConditionHistory = SWTFactory.createCombo(parent, SWT.DROP_DOWN | SWT.READ_ONLY, 1, null); initializeConditionHistoryDropDown(); fConditionHistory.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { int historyIndex = fConditionHistory.getSelectionIndex() - 1; if (historyIndex >= 0 && historyIndex != fSeparatorIndex) { fViewer.getDocument().set(getConditionHistory()[historyIndex]); } } }); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.widthHint = 10; fConditionHistory.setLayoutData(data); fLocalConditionHistory = new HashMap<IJavaLineBreakpoint, Stack<String>>(10); } fViewer = new JDISourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.LEFT_TO_RIGHT); fViewer.setEditable(false); ControlDecoration decoration = new ControlDecoration(fViewer.getControl(), SWT.TOP | SWT.LEFT); decoration.setShowOnlyOnFocus(true); FieldDecoration dec = FieldDecorationRegistry.getDefault() .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL); decoration.setImage(dec.getImage()); decoration.setDescriptionText(dec.getDescription()); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); // set height/width hints based on font GC gc = new GC(fViewer.getTextWidget()); gc.setFont(fViewer.getTextWidget().getFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gd.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 17); gd.widthHint = Dialog.convertWidthInCharsToPixels(fontMetrics, 40); gc.dispose(); fViewer.getControl().setLayoutData(gd); fContentAssistHandler = new AbstractHandler() { public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException { fViewer.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); return null; } }; fUndoHandler = new AbstractHandler() { public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException { fViewer.doOperation(ITextOperationTarget.UNDO); return null; } }; fRedoHandler = new AbstractHandler() { public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException { fViewer.doOperation(ITextOperationTarget.REDO); return null; } }; fHandlerService = (IHandlerService) PlatformUI.getWorkbench().getAdapter(IHandlerService.class); fViewer.getControl().addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { activateHandlers(); } @Override public void focusLost(FocusEvent e) { deactivateHandlers(); } }); parent.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { dispose(); } }); return parent; }