Java Code Examples for org.eclipse.swt.widgets.Control#setEnabled()

The following examples show how to use org.eclipse.swt.widgets.Control#setEnabled() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Create the filter area
 *
 * @param parent
 *            The parent composite
 * @return The filter area composite
 */
public Composite createFilterArea(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, true));
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    CheckboxTreeViewer treeViewer = createTreeViewer(composite);
    Control buttonComposite = createSelectionButtons(composite);
    GridData data = new GridData(GridData.FILL_BOTH);
    Tree treeWidget = treeViewer.getTree();
    treeWidget.setLayoutData(data);
    treeWidget.setFont(parent.getFont());
    if (fIsEmpty) {
        treeWidget.setEnabled(false);
        buttonComposite.setEnabled(false);
    }
    return composite;
}
 
Example 2
Source Project: arx   File: DialogComboSelection.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets or clears the error message. If not <code>null</code>, the OK button
 * is disabled.
 * 
 * @param errorMessage
 *            the error message, or <code>null</code> to clear
 * @since 3.0
 */
public void setErrorMessage(String errorMessage) {
    this.errorMessage = errorMessage;
    if (errorMessageText != null && !errorMessageText.isDisposed()) {
        errorMessageText.setText(errorMessage == null ? " \n " : errorMessage); //$NON-NLS-1$
        // Disable the error message text control if there is no error, or
        // no error text (empty or whitespace only). Hide it also to avoid
        // color change. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=130281
        boolean hasError = errorMessage != null && (StringConverter.removeWhiteSpaces(errorMessage)).length() > 0;
        errorMessageText.setEnabled(hasError);
        errorMessageText.setVisible(hasError);
        errorMessageText.getParent().update();
        // Access the ok button by id, in case clients have overridden
        // button creation. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=113643
        Control button = getButton(IDialogConstants.OK_ID);
        if (button != null) {
            button.setEnabled(errorMessage == null);
        }
    }
}
 
Example 3
Source Project: birt   File: GroupRenameDialog.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public void setErrorMessage( String errorMessage )
{
	this.errorMessage = errorMessage;
	if ( errorMessageText != null && !errorMessageText.isDisposed( ) )
	{
		errorMessageText.setText( errorMessage == null ? " \n " : errorMessage ); //$NON-NLS-1$
		// Disable the error message text control if there is no error, or
		// no error text (empty or whitespace only). Hide it also to avoid
		// color change.
		// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=130281
		boolean hasError = errorMessage != null
				&& ( StringConverter.removeWhiteSpaces( errorMessage ) ).length( ) > 0;
		errorMessageText.setEnabled( hasError );
		errorMessageText.setVisible( hasError );
		errorMessageText.getParent( ).update( );
		// Access the ok button by id, in case clients have overridden
		// button creation.
		// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=113643
		Control button = getButton( IDialogConstants.OK_ID );
		if ( button != null )
		{
			button.setEnabled( errorMessage == null );
		}
	}
}
 
Example 4
Source Project: hop   File: JsonInputDialog.java    License: Apache License 2.0 5 votes vote down vote up
private void setCompositeEnabled( Composite comp, boolean enabled ) {
  // TODO: move to TableView?
  comp.setEnabled( enabled );
  for ( Control child : comp.getChildren() ) {
    child.setEnabled( enabled );
  }
}
 
Example 5
private void updateControlsEnableState(List<Control> controls, boolean enable) {
	for (int i= controls.size() - 1; i >= 0; i--) {
		Control curr= controls.get(i);
		if (curr instanceof Composite) {
			updateControlsEnableState(Arrays.asList(((Composite)curr).getChildren()), enable);
		}
		curr.setEnabled(enable);
	}
}
 
Example 6
private void deactivate(final Composite parent) {
	for (final Control c : parent.getChildren()) {
		if (c instanceof Composite) {
			deactivate((Composite) c);
		} else {
			c.setEnabled(false);
		}
	}
}
 
Example 7
Source Project: arx   File: SWTUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * En-/disables the composite and its children.
 *
 * @param elem
 * @param val
 */
private static void setEnabled(final Composite elem, final boolean val) {
    elem.setEnabled(val);
    for (final Control c : elem.getChildren()) {
        if (c instanceof Composite) {
            setEnabled((Composite) c, val);
        } else {
            c.setEnabled(val);
        }
    }
}
 
Example 8
/**
 * Sets or clears the error message. If not <code>null</code>, the OK button is disabled.
 * @param errorMessage
 *            the error message, or <code>null</code> to clear
 * @since 3.0
 */
public void setErrorMessage(String errorMessage) {
	this.errorMessage = errorMessage;
	if (errorMessageText != null && !errorMessageText.isDisposed()) {
		String msg = errorMessageText.getText();
		msg = msg == null ? "" : msg;
		errorMessageText.setText(errorMessage == null ? "" : errorMessage); //$NON-NLS-1$
		// Disable the error message text control if there is no error, or
		// no error text (empty or whitespace only). Hide it also to avoid
		// color change.
		// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=130281
		boolean hasError = errorMessage != null && (StringConverter.removeWhiteSpaces(errorMessage)).length() > 0;
		errorMessageText.setEnabled(hasError);
		errorMessageText.setVisible(hasError);
		errorMessageText.getParent().update();
		String msg2 = errorMessageText.getText();
		if (!msg.equals(msg2) && initLocation != null && initSize != null) {
			Point p = getShell().computeSize(initSize.x, SWT.DEFAULT);
			getShell().setBounds(
					getConstrainedShellBounds(new Rectangle(initLocation.x, initLocation.y, initSize.x, p.y)));
		}
		// Access the ok button by id, in case clients have overridden button creation.
		// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=113643
		Control button = getButton(IDialogConstants.OK_ID);
		if (button != null) {
			button.setEnabled(errorMessage == null);
		}
	}
}
 
Example 9
Source Project: nebula   File: PWWidget.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Enable or disable the widget, depending on the associated enabler
 */
public boolean enableOrDisable() {
	if (this.enabler == null) {
		return true;
	}

	final boolean enabled = this.enabler.isEnabled();
	for (final Control c : this.controls) {
		if (!c.isDisposed()) {
			c.setEnabled(enabled);
		}
	}
	return enabled;
}
 
Example 10
/**
 * Toggles enabled/disabled state of the OK button based state of the error messages.
 */
private void toggleOK(boolean enabled) {
	Control button = getButton(OK_ID);
	if (button != null) {
		button.setEnabled(enabled);
	}
}
 
Example 11
@Override
public void createPartControl ( final Composite parent )
{
    parent.setLayout ( new FillLayout ( SWT.VERTICAL ) );
    createControls ( parent );

    // disable all
    for ( final Control control : this.controls )
    {
        control.setEnabled ( false );
    }

    addListener ();
}
 
Example 12
@Override
public void widgetSelected(SelectionEvent e) {

	for (int i= 0; i < controls.length; i++) {
		Control control= controls[i];
		control.setEnabled(!control.getEnabled());
	}
	validate();
}
 
Example 13
Source Project: logbook   File: LayoutLogic.java    License: MIT License 5 votes vote down vote up
/**
 * ウィジェットを無効または有効にします。
 * 
 * @param widget
 * @param enabled
 */
public static void enable(Control widget, boolean enabled) {
    if (widget instanceof Composite) {
        Control[] controls = ((Composite) widget).getChildren();
        for (Control control : controls) {
            enable(control, enabled);
        }
    }
    widget.setEnabled(enabled);
}
 
Example 14
private void restoreEnableState(Control w, Map h, String key) {
	if (w != null) {
		Boolean b = (Boolean) h.get(key);
		if (b != null) {
			w.setEnabled(b.booleanValue());
		}
	}
}
 
Example 15
/**
 * Note: this method should NEVER be called directly. Always use setVisible (the visibility control is the only
 * place that should reference this method).
 * 
 * @param updateFocus
 *            indicates if the focus should be given to the editor
 */
/* default */void hideFindBar(boolean updateFocus)
{
	if (findBarGridData.exclude == false)
	{
		sashGridData.exclude = true;
		separatorGridData.exclude = true;
		findBarGridData.exclude = true;
		composite.layout();
		findBarFinder.resetIncrementalOffset();
		findBarFinder.resetScope();
		removeComboSearchOnTextChangeListener();
		statusLineManager.setMessage(false, StringUtil.EMPTY, null);
	}
	if (updateFocus)
	{
		textEditor.setFocus();
	}
	if (disableWhenHidden != null)
	{
		for (Control w : disableWhenHidden)
		{
			w.setEnabled(false);
		}
	}

	sourceViewer.getTextWidget().removeFocusListener(textViewerFocusListener);
}
 
Example 16
/**
 * 根据当前操作不同的数据库类型,初始化界面 ;
 */
private void initUI(boolean isAdd) {
	MetaData curDbMetaData = dbMetaDataMap.get(getCurrDbType());

	if (!isAdd) {
		Control[] childrens = locationText.getParent().getChildren();
		for (Control c : childrens) {
			if (!(c instanceof Composite)) {
				if (c instanceof Text || c instanceof Button) {
					c.setEnabled(false);
				}
			} else {
				Composite com = (Composite) c;
				Control[] ch = com.getChildren();
				for (Control chl : ch) {
					if (c instanceof Text || c instanceof Button) {
						chl.setEnabled(false);
					}
				}
			}
		}
	} else {
		if (curDbMetaData.dataPathSupported()) {
			locationText.setEnabled(true);
			borwserBtn.setEnabled(true);
		} else {
			locationText.setEnabled(false);
			borwserBtn.setEnabled(false);
		}

		if (curDbMetaData.serverNameSupported()) {
			hostText.setEnabled(true);
		} else {
			hostText.setEnabled(false);
		}

		if (curDbMetaData.instanceSupported()) {
			instanceText.setEnabled(true);
		} else {
			instanceText.setEnabled(false);
		}

		if (curDbMetaData.portSupported()) {
			portText.setEnabled(true);
		} else {
			portText.setEnabled(false);
		}

		if (curDbMetaData.userNameSupported()) {
			usernameText.setEnabled(true);
		} else {
			usernameText.setEnabled(false);
		}

		if (curDbMetaData.passwordSupported()) {
			passwordText.setEnabled(true);
		} else {
			passwordText.setEnabled(false);
		}
	}
}
 
Example 17
private void enableControls(boolean enabled) {
    for (Control control : attributes.getChildren()) {
        control.setEnabled(enabled);
    }
}
 
Example 18
/**
 * Restores the enabled/disabled state of the given control.
 * 
 * @param w
 *            the control
 * @param h
 *            the map (key type: <code>String</code>, element type:
 *            <code>Boolean</code>)
 * @param key
 *            the key
 * @see #saveEnableStateAndSet
 */
private void restoreEnableState(Control w, Map h, String key) {
	if (w != null) {
		Boolean b = (Boolean) h.get(key);
		if (b != null) {
			w.setEnabled(b.booleanValue());
		}
	}
}
 
Example 19
Source Project: uima-uimaj   File: AbstractSection.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Enable ctrl.
 *
 * @param c the c
 * @param enabled the enabled
 */
protected static void enableCtrl(Control c, boolean enabled) {
  if (null != c)
    c.setEnabled(enabled);
}
 
Example 20
Source Project: arx   File: SWTUtil.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Disables the control.
 *
 * @param elem
 */
public static void disable(final Control elem) {
    elem.setEnabled(false);
}