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

The following examples show how to use org.eclipse.swt.widgets.Control#setEnabled() . 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
Source File: TraceTypePreferencePageViewer.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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 File: GroupRenameDialog.java    From birt with 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 3
Source File: DialogComboSelection.java    From arx with 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 4
Source File: JsonInputDialog.java    From hop with 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
Source File: FindBarDecorator.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 6
Source File: HsAbstractProgressDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
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 7
Source File: LayoutLogic.java    From logbook with 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 8
Source File: JavadocWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void widgetSelected(SelectionEvent e) {

	for (int i= 0; i < controls.length; i++) {
		Control control= controls[i];
		control.setEnabled(!control.getEnabled());
	}
	validate();
}
 
Example 9
Source File: QueryControlView.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@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 10
Source File: InstallNpmDependencyDialog.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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
Source File: PWWidget.java    From nebula with 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 12
Source File: InputDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 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()) {
		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 13
Source File: SWTUtil.java    From arx with 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 14
Source File: UserControlView.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private void deactivate(final Composite parent) {
	for (final Control c : parent.getChildren()) {
		if (c instanceof Composite) {
			deactivate((Composite) c);
		} else {
			c.setEnabled(false);
		}
	}
}
 
Example 15
Source File: ComplianceConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 16
Source File: IndentGuidePreferencePage.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
private void enableControls(boolean enabled) {
    for (Control control : attributes.getChildren()) {
        control.setEnabled(enabled);
    }
}
 
Example 17
Source File: TmDbManagerDialog.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 根据当前操作不同的数据库类型,初始化界面 ;
 */
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 18
Source File: TSWizardDialog.java    From tmxeditor8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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 File: AbstractSection.java    From uima-uimaj with 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 File: SWTUtil.java    From arx with 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);
}