Example usage for org.eclipse.jface.fieldassist ControlDecoration getControl

List of usage examples for org.eclipse.jface.fieldassist ControlDecoration getControl

Introduction

In this page you can find the example usage for org.eclipse.jface.fieldassist ControlDecoration getControl.

Prototype

public Control getControl() 

Source Link

Document

Get the control that is decorated by the receiver.

Usage

From source file:com.xored.af.ui.forms.parts.ControlDecorationAdapter.java

License:Open Source License

/**
 * @param decoration/* w  w  w. j a v a2  s  . c o m*/
 * @param object
 * @param feature
 * @param useQuickFix
 *            - use true for QuickFix on errors and grey control on not
 *            saved resource
 */
public ControlDecorationAdapter(final ControlDecoration decoration, final EObject object,
        final EStructuralFeature feature, final boolean useQuickFix) {
    this.useQuickFix = useQuickFix;
    this.decoration = decoration;
    this.object = object;
    this.feature = feature;
    if (decoration.getControl() != null) {
        this.originalBg = COLOR_DEF;
    } else {
        this.originalBg = null;
    }

    currentMarkers = new ArrayList<IMarker>();
    markerResolutions = new ArrayList<IMarkerResolution>();
    if (useQuickFix) {
        final IWorkspace workspace = ResourcesPlugin.getWorkspace();
        workspace.addResourceChangeListener(new IResourceChangeListener() {

            public void resourceChanged(final IResourceChangeEvent event) {
                final IResourceDelta delta = event.getDelta();
                if (delta != null && getTarget() != null) {
                    final IResourceDelta thisDelta = delta.findMember(getPlatformPath(getTarget()));
                    if (thisDelta == null || thisDelta.getMarkerDeltas() == null) {
                        return;
                    }
                    boolean changed = false;
                    for (final IMarkerDelta mdelta : thisDelta.getMarkerDeltas()) {
                        if (mdelta.getKind() == IResourceDelta.ADDED
                                && !currentMarkers.contains(mdelta.getMarker())) {
                            currentMarkers.add(mdelta.getMarker());
                            changed = true;
                        } else if (mdelta.getKind() == IResourceDelta.REMOVED) {
                            currentMarkers.remove(mdelta.getMarker());
                            changed = true;
                        }
                    }
                    if (changed && thisDelta.getResource() != null && thisDelta.getResource().exists()) {
                        final WorkspaceJob updateDecorationJob = new WorkspaceJob("Update control decoration") {

                            @Override
                            public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                                if (decoration.getControl() != null && !decoration.getControl().isDisposed()) {
                                    refreshResolutions();
                                    updateDecoration();
                                }
                                return Status.OK_STATUS;
                            }
                        };
                        updateDecorationJob.setRule(thisDelta.getResource());
                        updateDecorationJob.setUser(false);
                        updateDecorationJob.setSystem(true);
                        updateDecorationJob.schedule();
                    }
                }
            }
        });

    }

}

From source file:com.xored.af.ui.forms.parts.ControlDecorationUpdater.java

License:Open Source License

private synchronized void runUpdates() {
    final long startTime = System.currentTimeMillis();

    final Map<ControlDecoration, Update> updatesCopy = new HashMap<ControlDecoration, Update>(updates);
    updates.clear();/*from  www .  java  2 s.  c  om*/

    final int size = updatesCopy.size();
    int changes = 0;

    for (final Map.Entry<ControlDecoration, Update> entry : updatesCopy.entrySet()) {
        final ControlDecoration decoration = entry.getKey();
        // decoration itself may be already disposed, and also its control
        // may be disposed separately because of non-atomicity of disposal
        if (decoration.getControl() != null && !decoration.getControl().isDisposed()) {
            final Update update = entry.getValue();
            boolean changed = false;
            if (!equals(decoration.getImage(), update.image)) {
                decoration.setImage(update.image);
                changed = true;
            }
            if (!equals(decoration.getDescriptionText(), update.text)) {
                decoration.setDescriptionText(update.text);
                changed = true;
            }
            if (!equals(decoration.getControl().getBackground(), update.controlBg)) {
                decoration.getControl().setBackground(update.controlBg);
                changed = true;
            }
            if (changed) {
                changes++;
            }
        }
    }

    if (DEBUG) {
        AfUiPlugin.getDefault().info("Updated " + changes + " decorations in " + size + " requests in "
                + (System.currentTimeMillis() - startTime) + " millis");
    }
}

From source file:org.ebayopensource.turmeric.eclipse.ui.SOABasePage.java

License:Open Source License

/**
 * {@inheritDoc}//from   w w  w  . j a  v  a  2 s  . co  m
 */
@Override
public void addControlDecoration(Control control, ControlDecoration controlDecoration) {
    if (control != null && controlDecoration != null && controlDecoration.getControl() == control) {
        controlDecorations.put(control, controlDecoration);
    }
}

From source file:org.eclipse.rcptt.tesla.jface.ControlDecoratorRecordingHolder.java

License:Open Source License

public synchronized static List<ControlDecoration> getDecorators(Control ctrl) {
    List<ControlDecoration> result = new ArrayList<ControlDecoration>();
    List<WeakReference<ControlDecoration>> toRemove = new ArrayList<WeakReference<ControlDecoration>>();
    List<WeakReference<ControlDecoration>> values = decorations.get(ctrl);
    if (values == null) {
        return result;
    }//from   w w  w  .j ava  2 s. c o m
    for (WeakReference<ControlDecoration> controlDecoration : values) {
        ControlDecoration decoration = controlDecoration.get();
        if (decoration != null) {
            if (decoration.getControl() == null || decoration.getControl().isDisposed()) {
                toRemove.add(controlDecoration);
            } else {
                result.add(decoration);
            }
        } else {
            toRemove.add(controlDecoration);
        }
    }
    values.removeAll(toRemove);
    if (values.size() == 0) {
        decorations.remove(ctrl);
    }
    return result;
}

From source file:org.eclipse.wst.sse.sieditor.test.ui.v2.newtypedialog.NewTypeDialogTest.java

License:Open Source License

/**
 * Test method for/*  www.ja  v  a  2  s . c  om*/
 * {@link org.eclipse.wst.sse.sieditor.ui.v2.newtypedialog.NewTypeDialog#createNameComposite(org.eclipse.swt.widgets.Composite)}
 * .
 */
@Test
public final void testCreateNameComposite() {
    setUpCreateAndOpenMock();
    dialogExposed.createAndOpen();
    final Composite dialogArea = (Composite) dialogExposed.getShell().getChildren()[0];
    final Composite dialogContent = (Composite) dialogArea.getChildren()[0];
    final Control control = dialogContent.getChildren()[1];
    assertTrue(control instanceof Composite);
    final Composite nameComposite = (Composite) control;
    final Control[] children = nameComposite.getChildren();
    assertEquals(2, children.length);
    assertTrue(children[0] instanceof Label);
    assertEquals(Messages.NewTypeDialog_label_name, ((Label) children[0]).getText());
    assertTrue(children[1] instanceof Text);
    assertEquals(DEFAULT_NAME, ((Text) children[1]).getText());
    final ControlDecoration decoration = dialogExposed.getDecoration();
    assertEquals(decoration.getControl(), children[1]);
    assertEquals(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR)
            .getImage(), decoration.getImage());

    dialogExposed.buttonPressed(Dialog.CANCEL);
}

From source file:org.fusesource.ide.foundation.ui.util.ControlDecorationHelper.java

License:Open Source License

private void setImageAsynchronuously(final ControlDecoration decoration, final Image image) {
    Display.getDefault().asyncExec(() -> {
        if (!Widgets.isDisposed(decoration.getControl())) {
            decoration.setImage(image);/*from  w  ww . j ava 2  s  .c  o  m*/
        }
    });
}

From source file:org.jamon.eclipse.projectprefspage.JamonProjectPropertyPage.java

License:Mozilla Public License

private void addTemplateOuputInput(Composite composite) {
    Label templateOutputLabel = new Label(composite, SWT.NONE);
    templateOutputLabel.setText("Template output folder:");
    ControlDecoration outputField = new ControlDecoration(new Text(composite, SWT.SINGLE | SWT.BORDER),
            SWT.CENTER | SWT.LEFT, composite);
    templateOutputDirInput = (Text) outputField.getControl();
    String templateOutputDir = JamonNature.templateOutputFolderName(getProject());
    templateOutputDirInput//  w  w w.  j av a  2  s  . c om
            .setText((templateOutputDir != null) ? templateOutputDir : JamonNature.DEFAULT_OUTPUT_DIR);
    setDecoratedTextInputLayout(outputField);
    FieldDecoration requiredFieldIndicator = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
    outputField.setImage(requiredFieldIndicator.getImage());
}

From source file:org.jamon.eclipse.projectprefspage.JamonProjectPropertyPage.java

License:Mozilla Public License

private void setDecoratedTextInputLayout(ControlDecoration decoration) {
    GridData gd = new GridData(IDialogConstants.ENTRY_FIELD_WIDTH
            + FieldDecorationRegistry.getDefault().getMaximumDecorationWidth(), SWT.DEFAULT);
    gd.horizontalIndent = FieldDecorationRegistry.getDefault().getMaximumDecorationWidth();
    decoration.getControl().setLayoutData(gd);
}

From source file:org.marketcetera.photon.commons.ui.databinding.DataBindingUtils.java

/**
 * Attaches the control decoration to the control using the
 * {@value #CONTROL_DECORATION} key. This enables the decoration to be
 * accessed for testing purposes./*from ww  w .j ava2 s . co  m*/
 * 
 * @param decoration
 *            the decoration to attach to its control
 */
public static void attachControlDecoration(ControlDecoration decoration) {
    // add the decoration to the control for testing access
    decoration.getControl().setData(CONTROL_DECORATION, decoration);
}

From source file:org.pentaho.di.ui.core.widget.StyledTextComp.java

License:Apache License

public StyledTextComp(VariableSpace space, Composite parent, int args, String strTabName, boolean varsSensitive,
        boolean variableIconOnTop) {
    super(parent, SWT.NONE);
    this.varsSensitive = varsSensitive;
    this.variables = space;
    undoStack = new LinkedList<UndoRedoStack>();
    redoStack = new LinkedList<UndoRedoStack>();
    styledText = new StyledText(this, args);
    styledTextPopupmenu = new Menu(parent.getShell(), SWT.POP_UP);
    xParent = parent;//from ww w  .  j  av  a  2  s  .c o m
    this.strTabName = strTabName;
    // clipboard = new Clipboard(parent.getDisplay());
    this.setLayout(variableIconOnTop ? new FormLayout() : new FillLayout());
    buildingStyledTextMenu();
    addUndoRedoSupport();

    kls = new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == 'h' && (e.stateMask & SWT.MOD1 & SWT.SHIFT) != 0) {
                new StyledTextCompReplace(styledTextPopupmenu.getShell(), styledText).open();
            } else if (e.keyCode == 'z' && (e.stateMask & SWT.MOD1) != 0) {
                undo();
            } else if (e.keyCode == 'y' && (e.stateMask & SWT.MOD1) != 0) {
                redo();
            } else if (e.keyCode == 'a' && (e.stateMask & SWT.MOD1) != 0) {
                bFullSelection = true;
                styledText.selectAll();
            } else if (e.keyCode == 'f' && (e.stateMask & SWT.MOD1) != 0) {
                new StyledTextCompFind(styledTextPopupmenu.getShell(), styledText,
                        BaseMessages.getString(PKG, "WidgetDialog.Styled.Find")).open();
            }
        }
    };

    styledText.addKeyListener(kls);

    if (this.varsSensitive) {
        styledText.addKeyListener(new ControlSpaceKeyAdapter(this.variables, styledText));
        image = GUIResource.getInstance().getImageVariable();
        if (variableIconOnTop) {
            final Label wicon = new Label(this, SWT.RIGHT);
            PropsUI.getInstance().setLook(wicon);
            wicon.setToolTipText(BaseMessages.getString(PKG, "StyledTextComp.tooltip.InsertVariable"));
            wicon.setImage(image);
            wicon.setLayoutData(new FormDataBuilder().top().right(100, 0).result());
            styledText.setLayoutData(new FormDataBuilder().top(new FormAttachment(wicon, 0, 0)).left()
                    .right(100, 0).bottom(100, 0).result());
        } else {
            ControlDecoration controlDecoration = new ControlDecoration(styledText, SWT.TOP | SWT.RIGHT);
            controlDecoration.setImage(image);
            controlDecoration
                    .setDescriptionText(BaseMessages.getString(PKG, "StyledTextComp.tooltip.InsertVariable"));
            PropsUI.getInstance().setLook(controlDecoration.getControl());
        }
    }

    // Create the drop target on the StyledText
    DropTarget dt = new DropTarget(styledText, DND.DROP_MOVE);
    dt.setTransfer(new Transfer[] { TextTransfer.getInstance() });
    dt.addDropListener(new DropTargetAdapter() {
        public void dragOver(DropTargetEvent e) {
            styledText.setFocus();
            Point location = xParent.getDisplay().map(null, styledText, e.x, e.y);
            location.x = Math.max(0, location.x);
            location.y = Math.max(0, location.y);
            try {
                int offset = styledText.getOffsetAtLocation(new Point(location.x, location.y));
                styledText.setCaretOffset(offset);
            } catch (IllegalArgumentException ex) {
                int maxOffset = styledText.getCharCount();
                Point maxLocation = styledText.getLocationAtOffset(maxOffset);
                if (location.y >= maxLocation.y) {
                    if (location.x >= maxLocation.x) {
                        styledText.setCaretOffset(maxOffset);
                    } else {
                        int offset = styledText.getOffsetAtLocation(new Point(location.x, maxLocation.y));
                        styledText.setCaretOffset(offset);
                    }
                } else {
                    styledText.setCaretOffset(maxOffset);
                }
            }
        }

        public void drop(DropTargetEvent event) {
            // Set the buttons text to be the text being dropped
            styledText.insert((String) event.data);
        }
    });

}