/** Activate tooltip support for this control */ private void addOwnerControlListener() { removeOwnerControlsListener(); _ownerControl.addListener(SWT.Dispose, _ownerControlListener); _ownerControl.addListener(SWT.Resize, _ownerControlListener); }
private void handleNewFeature() { final Control control = fCategoryViewer.getControl(); BusyIndicator.showWhile( control.getDisplay(), new Runnable() { public void run() { IFeatureModel[] allModels = PDECore.getDefault().getFeatureModelManager().getModels(); ArrayList<IFeatureModel> newModels = new ArrayList<IFeatureModel>(); for (int i = 0; i < allModels.length; i++) { if (canAdd(allModels[i])) newModels.add(allModels[i]); } IFeatureModel[] candidateModels = newModels.toArray(new IFeatureModel[newModels.size()]); FeatureSelectionDialog dialog = new FeatureSelectionDialog( fCategoryViewer.getTree().getShell(), candidateModels, true); if (dialog.open() == Window.OK) { Object[] models = dialog.getResult(); try { doAdd(models); } catch (CoreException e) { PDEPlugin.log(e); } } } }); }
/** * {@inheritDoc} After the error remove is handled by its underlying {@link IEditErrorHandler}, * the original style will be applied to the editor control. */ @Override public void removeError(ICellEditor cellEditor) { super.removeError(cellEditor); if (this.errorStylingActive) { Control editorControl = cellEditor.getEditorControl(); // reset the rendering information to normal editorControl.setBackground(originalBgColor); editorControl.setForeground(originalFgColor); editorControl.setFont(originalFont); // ensure to reset the stored original values so possible // dynamic rendering aspects are also covered originalBgColor = null; originalFgColor = null; originalFont = null; if (decorationProvider != null) { decorationProvider.hideDecoration(); } this.errorStylingActive = false; } }
public static CellEditor createPropertyEditor( final IServiceLocator serviceLocator, Composite parent, DBPPropertySource source, DBPPropertyDescriptor property) { if (source == null) { return null; } final Object object = source.getEditableValue(); if (!property.isEditable(object)) { return null; } CellEditor cellEditor = UIUtils.createCellEditor(parent, object, property); if (cellEditor != null) { final Control editorControl = cellEditor.getControl(); UIUtils.addFocusTracker(serviceLocator, UIUtils.INLINE_WIDGET_EDITOR_ID, editorControl); editorControl.addDisposeListener( new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { UIUtils.removeFocusTracker(serviceLocator, editorControl); } }); } return cellEditor; }
private void updateOptionsDisplay() { boolean enabled = chkSegmentTarget.getSelection() || chkSegmentSource.getSelection(); grpOptions.setEnabled(enabled); for (Control ctrl : grpOptions.getChildren()) { ctrl.setEnabled(enabled); } }
/** Disposes all elements except the new content. content might be null to clear preview. */ private void setContent(Composite content) { for (Control c : container.getChildren()) { if (c != content) { c.dispose(); } } }
/* (non-Javadoc) * @see org.eclipse.swt.widgets.Layout#computeSize(org.eclipse.swt.widgets.Composite, int, int, boolean) */ @Override protected Point computeSize(Composite composite, int whint, int hhint, boolean flushCache) { int minX = Integer.MAX_VALUE; int minY = Integer.MAX_VALUE; int maxX = Integer.MIN_VALUE; int maxY = Integer.MIN_VALUE; for (Control kid : composite.getChildren()) { Point kidSize = kid.computeSize(-1, -1); Point kidOffs = kid.getLocation(); if (kidOffs.x < minX) minX = kidOffs.x; if (kidOffs.y < minY) minY = kidOffs.y; if (kidOffs.x + kidSize.x > maxX) maxX = kidOffs.x + kidSize.x; if (kidOffs.y + kidSize.y > maxY) maxY = kidOffs.y + kidSize.y; } if (whint > 0) { if (whint + minX > maxX) maxX = whint + minX; } if (hhint > 0) { if (hhint + minY > maxY) maxY = hhint + minY; } return new Point(maxX - minX, maxY - minY); }
public void initControl(Control control) { control.setFont(iniAppearance.getFontGlobal()); control.setBackground(iniAppearance.getColorBackground()); control.setForeground(iniAppearance.getColorForeground()); controls.add(control); }
public void applyFont(FontType type, FontData data) { Font newFont = new Font(SwtUtils.DISPLAY, data); Font oldFont = null; switch (type) { case GLOBAL: { oldFont = iniAppearance.getFontGlobal(); for (Control control : controls) { if (control.isDisposed()) continue; control.setFont(newFont); } for (Label label : labels) { if (label.isDisposed()) continue; label.setFont(newFont); } for (Button button : buttons) { if (button.isDisposed()) continue; button.setFont(newFont); } iniAppearance.setFontGlobal(newFont); break; } case LOG: { oldFont = iniAppearance.getFontLog(); for (StyledText control : logControls) { if (control.isDisposed()) continue; control.setFont(newFont); } iniAppearance.setFontLog(newFont); break; } case CHAT: { oldFont = iniAppearance.getFontChat(); for (Text control : chatControls) { if (control.isDisposed()) continue; control.setFont(newFont); } iniAppearance.setFontChat(newFont); break; } } if (oldFont != null) oldFont.dispose(); }
private Composite createMarkersTabContent(Composite folder) { GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; layout.numColumns = 2; PixelConverter conv = new PixelConverter(folder); Composite markersComposite = new Composite(folder, SWT.NULL); markersComposite.setLayout(layout); markersComposite.setFont(folder.getFont()); GridData data = new GridData(GridData.FILL_BOTH); data.widthHint = conv.convertWidthInCharsToPixels(50); Control listControl = fTodoTasksList.getListControl(markersComposite); listControl.setLayoutData(data); Control buttonsControl = fTodoTasksList.getButtonBox(markersComposite); buttonsControl.setLayoutData( new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING)); fCaseSensitiveCheckBox.doFillIntoGrid(markersComposite, 2); return markersComposite; }
private void deactivate() { if (fKeyListener != null) { Control control = fNavigable.getControl(); if (!control.isDisposed()) control.removeKeyListener(fKeyListener); fKeyListener = null; } }
/** * This does the work of laying out our controls. * * @see org.eclipse.swt.widgets.Layout#layout(org.eclipse.swt.widgets.Composite, boolean) */ protected void layout(Composite composite, boolean flushCache) { getControls(composite); Rectangle rect = composite.getClientArea(); int left = rect.x, right = rect.width, top = rect.y, bottom = rect.height; if (north != null) { Point pt = getSize(north, flushCache); north.setBounds(left, top, rect.width, pt.y); top += pt.y; } if (south != null) { Point pt = getSize(south, flushCache); south.setBounds(left, rect.height - pt.y, rect.width, pt.y); bottom -= pt.y; } if (east != null) { Point pt = getSize(east, flushCache); east.setBounds(rect.width - pt.x, top, pt.x, (bottom - top)); right -= pt.x; } if (west != null) { Point pt = getSize(west, flushCache); west.setBounds(left, top, pt.x, (bottom - top)); left += pt.x; } if (center != null) { center.setBounds(left, top, (right - left), (bottom - top)); } }
void computeSize(Control control, int wHint, int hHint, boolean flushCache) { if (cacheWidth != -1 && cacheHeight != -1) return; if (wHint == this.widthHint && hHint == this.heightHint) { if (defaultWidth == -1 || defaultHeight == -1 || wHint != defaultWhint || hHint != defaultHhint) { Point size = control.computeSize(wHint, hHint, flushCache); defaultWhint = wHint; defaultHhint = hHint; defaultWidth = size.x; defaultHeight = size.y; } cacheWidth = defaultWidth; cacheHeight = defaultHeight; return; } if (currentWidth == -1 || currentHeight == -1 || wHint != currentWhint || hHint != currentHhint) { Point size = control.computeSize(wHint, hHint, flushCache); currentWhint = wHint; currentHhint = hHint; currentWidth = size.x; currentHeight = size.y; } cacheWidth = currentWidth; cacheHeight = currentHeight; }
private Rectangle getDisplayBounds(final Point location) { Rectangle displayBounds; final Monitor[] allMonitors = _ownerControl.getDisplay().getMonitors(); if (allMonitors.length > 1) { // By default present in the monitor of the control displayBounds = _ownerControl.getMonitor().getBounds(); final Point p = new Point(location.x, location.y); // Search on which monitor the event occurred Rectangle tmp; for (final Monitor element : allMonitors) { tmp = element.getBounds(); if (tmp.contains(p)) { displayBounds = tmp; break; } } } else { displayBounds = _ownerControl.getDisplay().getBounds(); } return displayBounds; }
@Override public boolean applyCSSProperty( Object element, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { Widget widget = SWTElementHelpers.getWidget(element); if (widget instanceof CTabItem) { Item item = (Item) widget; boolean showClose = ((Boolean) engine.convert(value, Boolean.class, null)).booleanValue(); if ("selected".equals(pseudo)) { Control parent = getParent(widget); ShowCloseSelectionListener listener = (ShowCloseSelectionListener) parent.getData(CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY); if (listener == null) { listener = new ShowCloseSelectionListener(engine); parent.addListener(SWT.Paint, listener); parent.setData(CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY, listener); } else { listener.setEngine(engine); } item = getSelection(getParent(widget)); listener.setSelection(item); if (item != null) { setShowClose(item, showClose); } } else { setShowClose(item, showClose); } return true; } return false; }
@Override protected Control createControl(final Composite parent) { final Control control = super.createControl(parent); control.addTraverseListener( new TraverseListener() { @Override public void keyTraversed(TraverseEvent e) { switch (e.keyCode) { case SWT.ARROW_LEFT: case SWT.ARROW_RIGHT: case SWT.ARROW_UP: case SWT.ARROW_DOWN: case SWT.TAB: fireApplyEditorValue(); deactivate(); final Event event = new Event(); event.character = e.character; event.keyCode = e.keyCode; event.stateMask = e.stateMask; parent.notifyListeners(SWT.KeyDown, event); } } }); return control; }
/** resets the model and view to its initial state */ public void reset() { Control[] children = parent.getChildren(); for (Control control : children) { control.dispose(); } createPartControl(parent); }
protected void handleModify(final Control control) { if (control.equals(_entityClassNameText)) { updateFeature(_binding, "entityClassName", _entityClassNameText.getText().trim()); } else if (control.equals(_persistenceUnitText)) { updateFeature(_binding, "persistenceUnit", _persistenceUnitText.getText().trim()); } else if (control.equals(_transcationManagerText)) { updateFeature(_binding, "transactionManager", _transcationManagerText.getText().trim()); } else if (control.equals(_deleteCheckbox)) { updateConsumeFeature("consumeDelete", _deleteCheckbox.getSelection()); } else if (control.equals(_lockEntityCheckbox)) { updateConsumeFeature("consumeLockEntity", _lockEntityCheckbox.getSelection()); } else if (control.equals(_maximumResultsText)) { try { Integer port = new Integer(_maximumResultsText.getText().trim()); updateConsumeFeature("maximumResults", port.intValue()); } catch (NumberFormatException nfe) { updateConsumeFeature("maximumResults", _maximumResultsText.getText().trim()); } } else if (control.equals(_queryText)) { updateConsumeFeature("consumerQuery", _queryText.getText().trim()); } else if (control.equals(_namedQueryText)) { updateConsumeFeature("consumerNamedQuery", _namedQueryText.getText().trim()); } else if (control.equals(_nativeQueryText)) { updateConsumeFeature("consumerNativeQuery", _nativeQueryText.getText().trim()); } else if (control.equals(_transactedCheckbox)) { updateConsumeFeature("consumerTransacted", _transactedCheckbox.getSelection()); } else { super.handleModify(control); } validate(); setHasChanged(false); setDidSomething(true); }
/** * Perform any cleanup necessary to exit the program (save configuration, etc). * * @see org.eclipse.jface.window.Window#close() */ public boolean close() { try { int modified = modifiedCount(); if (modified > 0) { MessageBox message = new MessageBox(getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); message.setMessage(modified + " document(s) not saved, still exit?"); int confirm = message.open(); if (confirm == SWT.NO) { return false; } } Point currentSize = this.getShell().getSize(); config.setInitialSize(currentSize.x, currentSize.y); config.save(); CTabItem[] items = tabFolder.getItems(); for (int i = items.length - 1; i >= 0; --i) { Control control = items[i].getControl(); if (control instanceof WikiViewer) { ((WikiViewer) control).dispose(); } else { LOG.debug("Control is not of type WikiViewer : " + control.getClass().getName()); } } } catch (ConfigurationException e) { logError("Cannot save configuration", e); } return super.close(); }
protected void handleUndo(Control control) { if (_binding != null) { if (control.equals(_entityClassNameText)) { _entityClassNameText.setText(this._binding.getEntityClassName()); } else if (control.equals(_persistenceUnitText)) { _persistenceUnitText.setText(this._binding.getPersistenceUnit().toString()); } else if (control.equals(_transcationManagerText)) { _transcationManagerText.setText(this._binding.getTransactionManager()); } else if (control.equals(_deleteCheckbox)) { _deleteCheckbox.setSelection(this._binding.getConsume().isConsumeDelete()); } else if (control.equals(_lockEntityCheckbox)) { _lockEntityCheckbox.setSelection(this._binding.getConsume().isConsumeLockEntity()); } else if (control.equals(_maximumResultsText)) { setTextValue( _maximumResultsText, PropTypeUtil.getPropValueString(this._binding.getConsume().getMaximumResults())); } else if (control.equals(_queryText)) { _queryText.setText(this._binding.getConsume().getConsumerQuery()); } else if (control.equals(_namedQueryText)) { _namedQueryText.setText(this._binding.getConsume().getConsumerNamedQuery()); } else if (control.equals(_nativeQueryText)) { _nativeQueryText.setText(this._binding.getConsume().getConsumerNativeQuery()); } else if (control.equals(_transactedCheckbox)) { _transactedCheckbox.setSelection(this._binding.getConsume().isConsumerTransacted()); } else { super.handleUndo(control); } } setHasChanged(false); }
/** * Force the repainting of the control (the only way found to accomplish this, is to reset its * bounds, and set again its original ones) * * @param control the control to be repainted */ public static void forceRepaint(Control control) { // Locals Rectangle bounds = control.getBounds(); control.setBounds(0, 0, 0, 0); control.setBounds(bounds); }
private void enableOK() { Control button = getButton(IDialogConstants.OK_ID); if (button != null) { button.setEnabled(true); } }
/** * excludes a control from the Layout calculation * * @param that * @param hideit */ private void hideObject(final Control that, final boolean hideit) { GridData GData = (GridData) that.getLayoutData(); GData.exclude = true && hideit; that.setVisible(true && !hideit); Control[] myArray = {that}; layout(myArray); }
@Override protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); POPUP_LAYOUT_FACTORY.applyTo(composite); // LAYOUTDATA_GRAB_BOTH.applyTo(composite); GridData gd = LAYOUTDATA_GRAB_BOTH.create(); composite.setLayoutData(gd); if (hasTitleArea()) { createTitleMenuArea(composite); createHorizontalSeparator(composite); } dialogArea = createDialogArea(composite); if (dialogArea.getLayoutData() == null) LAYOUTDATA_GRAB_BOTH.applyTo(composite); gd = LAYOUTDATA_GRAB_BOTH.create(); dialogArea.pack(); gd.widthHint = dialogArea.getSize().x; gd.heightHint = dialogArea.getSize().y; dialogArea.setLayoutData(gd); if (hasInfoArea()) { createHorizontalSeparator(composite); createInfoTextArea(composite); } return composite; }
private boolean isDisplayThread() { Control ctrl = fViewer.getControl(); if (ctrl == null) return false; Display currentDisplay = Display.getCurrent(); return currentDisplay != null && currentDisplay.equals(ctrl.getDisplay()); }
protected Control createListChangeControl(Composite parent) { GridData gd; Control control; if (composite == null) composite = new Composite(parent, SWT.NONE); composite.setBackground(parent.getBackground()); GridLayout gridLayout = new GridLayout(3, false); gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; gridLayout.horizontalSpacing = 0; gridLayout.verticalSpacing = 0; composite.setLayout(gridLayout); Control listControl = createListControl(composite); gd = new GridData(GridData.FILL_BOTH); listControl.setLayoutData(gd); control = new Label(composite, SWT.NONE); control.setBackground(parent.getBackground()); gd = new GridData(); gd.widthHint = 5; control.setLayoutData(gd); control = getChangeControl(composite); return composite; }
/** * @see ch.post.pf.gui.ocp.wt.ext.dialogs.OcpDialog#showDialogFor(org.eclipse.swt.widgets.Control) */ public int showDialogFor(Control field) { create(); getShell() .addShellListener( new ShellAdapter() { @Override public void shellDeactivated(ShellEvent e) { close(); } }); // make sure that the popup fit into the application window. Rectangle appBounds = getEnvironment().getDisplay().getBounds(); Point absPrefPos = field.toDisplay(field.getSize().x - getShell().getSize().x, field.getSize().y); Rectangle prefBounds = new Rectangle(absPrefPos.x, absPrefPos.y, getShell().getSize().x, getShell().getSize().y); // horizontal correction if (prefBounds.x + prefBounds.width > appBounds.width) { prefBounds.x = appBounds.width - prefBounds.width; } // vertical correciton if (prefBounds.y + prefBounds.height > appBounds.height) { prefBounds.y = appBounds.height - prefBounds.height; } getShell().setLocation(prefBounds.x, prefBounds.y); int ret = this.open(); return ret; }
/** 销毁除了“过滤器列表控件”之外的其它控件 */ private void disposeChild() { for (Control ctl : this.getChildren()) { if (!"filterName".equals(ctl.getData()) && ctl != null && !ctl.isDisposed()) { ctl.dispose(); } } }
public void runViewUpdate(final Runnable runnable, final boolean preserveExpansion) { if (Utils.canUpdateViewer(getViewer()) || isPerformingBackgroundUpdate()) { internalRunViewUpdate(runnable, preserveExpansion); } else { if (Thread.currentThread() != getEventHandlerJob().getThread()) { // Run view update should only be called from the UI thread or // the update handler thread. // We will log the problem for now and make it an assert later TeamUIPlugin.log( IStatus.WARNING, "View update invoked from invalid thread", new TeamException( "View update invoked from invalid thread")); //$NON-NLS-1$ //$NON-NLS-2$ } final Control ctrl = getViewer().getControl(); if (ctrl != null && !ctrl.isDisposed()) { ctrl.getDisplay() .syncExec( new Runnable() { public void run() { if (!ctrl.isDisposed()) { BusyIndicator.showWhile( ctrl.getDisplay(), new Runnable() { public void run() { internalRunViewUpdate(runnable, preserveExpansion); } }); } } }); } } }
private Object aboutToStart(boolean cancelable) { Map savedState = null; Shell shell = getShell(); if (shell != null) { // Save focus control Control focusControl = getShell().getDisplay().getFocusControl(); if (focusControl != null && focusControl.getShell() != getShell()) focusControl = null; Button cancelButton = getButton(IDialogConstants.CANCEL_ID); // Set the busy cursor to all shells. Display d = getShell().getDisplay(); setDisplayCursor(d, d.getSystemCursor(SWT.CURSOR_WAIT)); // Set the arrow cursor to the cancel component. cancelButton.setCursor(d.getSystemCursor(SWT.CURSOR_ARROW)); boolean hasProgressMonitor = fProgressMonitorPart != null; // Deactivate shell savedState = saveUIState(false); if (focusControl != null) savedState.put("focus", focusControl); // $NON-NLS-1$ if (hasProgressMonitor) { if (cancelable) fProgressMonitorPart.attachToCancelComponent(cancelButton); fStatusContainer.showPage(fProgressMonitorPart); } // Update the status container since we are blocking the event loop right now. fStatusContainer.update(); } return savedState; }