Example usage for org.eclipse.jface.util Assert isTrue

List of usage examples for org.eclipse.jface.util Assert isTrue

Introduction

In this page you can find the example usage for org.eclipse.jface.util Assert isTrue.

Prototype

public static boolean isTrue(boolean expression, String message) 

Source Link

Document

Asserts that the given boolean is true.

Usage

From source file:ca.uwaterloo.gp.fmp.presentation.MultiLineTableCellEditor.java

License:Open Source License

/**
 * Processes a modify event that occurred in this text cell editor.
 * This framework method performs validation and sets the error message
 * accordingly, and then reports a change via <code>fireEditorValueChanged</code>.
 * Subclasses should call this method at appropriate times. Subclasses
 * may extend or reimplement.//from   ww w .j a v  a  2  s. c  om
 *
 * @param e the SWT modify event
 */
protected void editOccured(ModifyEvent e) {
    String value = text.getText();
    if (value == null)
        value = "";//$NON-NLS-1$
    Object typedValue = value;
    boolean oldValidState = isValueValid();
    boolean newValidState = isCorrect(typedValue);
    if (typedValue == null && newValidState)
        Assert.isTrue(false, "Validator isn't limiting the cell editor's type range");//$NON-NLS-1$
    if (!newValidState) {
        // try to insert the current value into the error message.
        setErrorMessage(MessageFormat.format(getErrorMessage(), new Object[] { value }));
    }
    valueChanged(oldValidState, newValidState);
}

From source file:com.agynamix.platform.frontend.preferences.PasswordFieldEditor.java

License:Open Source License

/**
 * Returns this field editor's text control.
 * <p>//from  w ww  .j  av a2s .  c  om
 * The control is created if it does not yet exist
 * </p>
 * 
 * @param parent
 *            the parent
 * @return the text control
 */
public Text getTextControl(Composite parent) {
    if (textField == null) {
        textField = new Text(parent, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
        textField.setFont(parent.getFont());
        switch (validateStrategy) {
        case VALIDATE_ON_KEY_STROKE:
            textField.addKeyListener(new KeyAdapter() {

                /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent)
                 */
                public void keyReleased(KeyEvent e) {
                    valueChanged();
                }
            });

            break;
        case VALIDATE_ON_FOCUS_LOST:
            textField.addKeyListener(new KeyAdapter() {

                public void keyPressed(KeyEvent e) {
                    clearErrorMessage();
                }
            });
            textField.addFocusListener(new FocusAdapter() {

                public void focusGained(FocusEvent e) {
                    refreshValidState();
                }

                public void focusLost(FocusEvent e) {
                    valueChanged();
                    clearErrorMessage();
                }
            });
            break;
        default:
            Assert.isTrue(false, "Unknown validate strategy");//$NON-NLS-1$
        }
        textField.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent event) {
                textField = null;
            }
        });
        if (textLimit > 0) {//Only set limits above 0 - see SWT spec
            textField.setTextLimit(textLimit);
        }
    } else {
        checkParent(textField, parent);
    }
    return textField;
}

From source file:com.aptana.ide.core.ui.widgets.TextFieldEditor.java

License:Open Source License

/**
 * Returns this field editor's text control.
 * <p>//from  w  w w  .j a  v  a2s.  co m
 * The control is created if it does not yet exist
 * </p>
 * 
 * @param parent
 *            the parent
 * @return the text control
 */
public Text getTextControl(Composite parent) {
    if (textField == null) {
        textField = new Text(parent, style);
        textField.setFont(parent.getFont());
        switch (validateStrategy) {
        case VALIDATE_ON_KEY_STROKE:
            textField.addKeyListener(new KeyAdapter() {

                /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent)
                 */
                public void keyReleased(KeyEvent e) {
                    valueChanged();
                }
            });

            break;
        case VALIDATE_ON_FOCUS_LOST:
            textField.addKeyListener(new KeyAdapter() {
                public void keyPressed(KeyEvent e) {
                    clearErrorMessage();
                }
            });
            textField.addFocusListener(new FocusAdapter() {
                public void focusGained(FocusEvent e) {
                    refreshValidState();
                }

                public void focusLost(FocusEvent e) {
                    valueChanged();
                    clearErrorMessage();
                }
            });
            break;
        default:
            Assert.isTrue(false, "Unknown validate strategy");//$NON-NLS-1$
        }
        textField.addDisposeListener(new DisposeListener() {
            public void widgetDisposed(DisposeEvent event) {
                textField = null;
            }
        });
        if (textLimit > 0) {// Only set limits above 0 - see SWT spec
            textField.setTextLimit(textLimit);
        }
    } else {
        checkParent(textField, parent);
    }
    return textField;
}

From source file:com.architexa.org.eclipse.gef.ui.actions.ZoomComboContributionItem.java

License:Open Source License

/**
 * The control item implementation of this <code>IContributionItem</code>
 * method throws an exception since controls cannot be added to menus.
 * /* ww w.ja  v a 2s .  c o m*/
 * @param parent The menu
 * @param index Menu index
 */
public final void fill(Menu parent, int index) {
    Assert.isTrue(false, "Can't add a control to a menu");//$NON-NLS-1$
}

From source file:com.architexa.org.eclipse.gef.ui.parts.AbstractEditPartViewer.java

License:Open Source License

/**
 * @see EditPartViewer#setContents(Object)
 *//*from  w ww .  j a  v  a 2s.com*/
public void setContents(Object contents) {
    Assert.isTrue(getEditPartFactory() != null, "An EditPartFactory is required to call setContents(Object)");//$NON-NLS-1$
    setContents(getEditPartFactory().createEditPart(null, contents));
}

From source file:com.iw.plugins.spindle.ui.ChooseFromNamespaceWidget.java

License:Mozilla Public License

/**
 * Method checkAcceptFlags./*w  w w.  j  a  va 2 s .  c o m*/
 * @param acceptFlags
 */
private void checkAcceptFlags(int acceptFlags) {

    boolean components = (acceptFlags & TapestryNamespaceLookup.ACCEPT_COMPONENTS) > 0;
    boolean pages = (acceptFlags & TapestryNamespaceLookup.ACCEPT_PAGES) > 0;

    Assert.isTrue(!(components && pages), "error: trying to lookup both pages & components!");
    Assert.isTrue((components || pages), "error: must seach for one of pages or components");

    this.acceptFlags = acceptFlags;

}

From source file:com.jasperassistant.designer.viewer.actions.PageNumberContributionItem.java

License:Open Source License

public final void fill(Menu parent, int index) {
    Assert.isTrue(false, "Can't add page number to a menu");//$NON-NLS-1$
}

From source file:com.jasperassistant.designer.viewer.actions.StatusContributionItem.java

License:Open Source License

/**
 * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.Menu,
 *      int)// w  w w.  ja va 2 s .  c o m
 */
public final void fill(Menu parent, int index) {
    Assert.isTrue(false, Messages.getString("StatusContributionItem.cannotAddToMenu")); //$NON-NLS-1$
}

From source file:com.jasperassistant.designer.viewer.actions.ZoomComboContributionItem.java

License:Open Source License

/**
 * @see org.eclipse.jface.action.IContributionItem#fill(org.eclipse.swt.widgets.Menu,
 *      int)/*from  w  w  w .j  av a  2s  . co  m*/
 */
public final void fill(Menu parent, int index) {
    Assert.isTrue(false, Messages.getString("ZoomComboContributionItem.cannotAddToMenu")); //$NON-NLS-1$
}

From source file:com.jasperassistant.designer.viewer.ReportViewer.java

License:Open Source License

/**
 * @see com.jasperassistant.designer.viewer.IReportViewer#setDocument(net.sf.jasperreports.engine.JasperPrint)
 *//*from   w ww .j av  a 2 s  .c o  m*/
public void setDocument(JasperPrint document) {
    Assert.isNotNull(document, Messages.getString("ReportViewer.documentNotNull")); //$NON-NLS-1$
    Assert.isNotNull(document.getPages(), Messages.getString("ReportViewer.documentNotEmpty")); //$NON-NLS-1$
    Assert.isTrue(!document.getPages().isEmpty(), Messages.getString("ReportViewer.documentNotEmpty")); //$NON-NLS-1$

    this.document = document;
    this.reason = null;
    this.pageIndex = Math.min(Math.max(0, pageIndex), getPageCount() - 1);
    setZoomInternal(computeZoom());
    fireViewerModelChanged();
}