Java Code Examples for org.eclipse.jface.fieldassist.ControlDecoration#hide()

The following examples show how to use org.eclipse.jface.fieldassist.ControlDecoration#hide() . 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: ClaferValidation.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * check if the given string is a valid clafer name and use the {@link ControlDecoration} to give feedback
 *
 * @param claferName {@link String} name to be tested
 * @param decoration {@link ControlDecoration} to display the error message in, hide if the string is valid
 * @return
 */
public static boolean validateClaferName(final String claferName, final boolean required, final ControlDecoration decoration) {
	boolean valid = true;

	final String result = getNameValidationMessage(claferName, required);
	if (!result.isEmpty()) {
		decoration.setImage(UIConstants.DEC_ERROR);
		decoration.setDescriptionText(result);
		decoration.show();
		valid = false;
	} else {
		decoration.hide();
	}

	return valid;
}
 
Example 2
Source File: ServerPortExtension.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
public void createControl(UI_POSITION position, Composite parent) {
  // We add controls only to the BOTTOM position.
  if (position == UI_POSITION.BOTTOM) {
    portLabel = new Label(parent, SWT.NONE);
    portLabel.setVisible(false);
    portLabel.setText(Messages.getString("NEW_SERVER_DIALOG_PORT"));

    portText = new Text(parent, SWT.SINGLE | SWT.BORDER);
    portText.setVisible(false);
    portText.setText(String.valueOf(LocalAppEngineServerBehaviour.DEFAULT_SERVER_PORT));
    portText.addVerifyListener(new PortChangeMonitor());
    portText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();
    Image errorImage = registry.getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage();

    portDecoration = new ControlDecoration(portText, SWT.LEFT | SWT.TOP);
    portDecoration.setDescriptionText(Messages.getString("NEW_SERVER_DIALOG_INVALID_PORT_VALUE"));
    portDecoration.setImage(errorImage);
    portDecoration.hide();
  }
}
 
Example 3
Source File: FieldAssistHelper.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void showContentAssistDecoration( AssistField smartField,
		boolean show )
{
	FieldDecoration dec = getCueDecoration( );
	ControlDecoration cd = smartField.controlDecoration;
	if ( show )
	{
		cd.setImage( dec.getImage( ) );
		cd.setDescriptionText( dec.getDescription( ) );
		cd.setShowOnlyOnFocus( true );
		cd.show( );
	}
	else
	{
		cd.hide( );
	}
}
 
Example 4
Source File: FieldAssistHelper.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void showWarningDecoration( AssistField smartField, boolean show )
{
	FieldDecoration dec = smartField.getWarningDecoration( );
	ControlDecoration cd = smartField.controlDecoration;
	if ( show )
	{
		cd.setImage( dec.getImage( ) );
		cd.setDescriptionText( dec.getDescription( ) );
		cd.setShowOnlyOnFocus( false );
		cd.show( );
	}
	else
	{
		cd.hide( );
	}
}
 
Example 5
Source File: FieldAssistHelper.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void showErrorDecoration( AssistField smartField, boolean show )
{
	FieldDecoration dec = smartField.getErrorDecoration( );
	ControlDecoration cd = smartField.controlDecoration;
	if ( show )
	{
		cd.setImage( dec.getImage( ) );
		cd.setDescriptionText( dec.getDescription( ) );
		cd.setShowOnlyOnFocus( false );
		cd.show( );
	}
	else
	{
		cd.hide( );
	}
}
 
Example 6
Source File: GenericTransactionWizard.java    From offspring with MIT License 6 votes vote down vote up
public void requestVerification() {
  boolean verified = true;
  for (IGenericTransactionField field : transaction.getFields()) {
    String[] message = new String[1];
    ControlDecoration deco = decorators.get(field.getLabel());
    if (field.verify(message)) {
      deco.hide();
    }
    else {
      deco.setDescriptionText(message[0]);
      deco.show();
      verified = false;
    }
  }

  createPage._canFlipToNextPage = verified;
  try {
    getContainer().updateButtons();
  }
  catch (Exception e) {}
}
 
Example 7
Source File: PatternExpressionViewer.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void createTextViewer() {
	viewer = createViewer(mc);
	viewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
	configureTextViewer();
	addLineStyleListener();
	helpDecoration = new ControlDecoration(viewer.getControl(), SWT.TOP | SWT.RIGHT, this);
	helpDecoration.setImage(JFaceResources.getImage(Dialog.DLG_IMG_HELP));
	helpDecoration.setDescriptionText(Messages.patternViewerHint);
	helpDecoration.setMarginWidth(2);
	helpDecoration.hide();

	hintDecoration = new ControlDecoration(viewer.getControl(), SWT.TOP | SWT.LEFT, this);
	hintDecoration.setImage(Pics.getImage(PicsConstants.hint));
	hintDecoration.setMarginWidth(2);
	hintDecoration.setShowHover(true);
	hintDecoration.setShowOnlyOnFocus(true);
	hintDecoration.hide();

	viewer.addTextListener(new ITextListener() {

		@Override
		public void textChanged(final TextEvent event) {
			viewer.getTextWidget().notifyListeners(SWT.Modify, new Event());
		}
	});

	helpDecoration.show();
}
 
Example 8
Source File: ClaferValidation.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean validateClaferInheritance(final String inheritanceName, final boolean required, final ControlDecoration decoration) {
	boolean valid = true;

	final String result = getInheritanceValidationMessage(inheritanceName, required);
	if (!result.isEmpty()) {
		decoration.setImage(UIConstants.DEC_ERROR);
		decoration.setDescriptionText(result);
		decoration.show();
		valid = false;
	} else {
		decoration.hide();
	}

	return valid;
}
 
Example 9
Source File: GenericTransactionWizard.java    From offspring with MIT License 5 votes vote down vote up
@Override
public void createControl(Composite parent) {
  Composite composite = new Composite(parent, SWT.NONE);
  GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10)
      .spacing(20, 5).applyTo(composite);

  /* generate the wizard fields */
  for (IGenericTransactionField field : transaction.getFields()) {
    Label label = new Label(composite, SWT.NONE);
    label.setText(field.getLabel());

    Control control = field.createControl(composite);
    if (control instanceof Text && (control.getStyle() & SWT.V_SCROLL) != 0) {
      GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL)
          .grab(true, true).applyTo(control);
    }
    else {
      GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
          .grab(true, false).applyTo(control);
    }
    ControlDecoration deco = new ControlDecoration(control, SWT.TOP
        | SWT.RIGHT);
    deco.setImage(errorImage);
    deco.hide();
    decorators.put(field.getLabel(), deco);
  }
  setControl(composite);
}
 
Example 10
Source File: PromptFeeDeadline.java    From offspring with MIT License 4 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
  Composite container = (Composite) super.createDialogArea(parent);
  GridLayout layout = new GridLayout(2, false);
  layout.marginRight = 5;
  layout.marginLeft = 10;
  container.setLayout(layout);

  Label feeLabel = new Label(container, SWT.NONE);
  feeLabel.setText("Fee");

  feeText = new Text(container, SWT.BORDER);
  feeText
      .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
  feeText.setText(Integer.toString(minimumFee));

  decoFee = new ControlDecoration(feeText, SWT.TOP | SWT.RIGHT);
  decoFee.setImage(errorImage);
  decoFee.hide();

  Label deadlineLabel = new Label(container, SWT.NONE);
  deadlineLabel.setText("Deadline");

  deadlineText = new Text(container, SWT.BORDER);
  deadlineText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
      1, 1));
  deadlineText.setText(Integer.toString(deadline));

  decoDeadline = new ControlDecoration(deadlineText, SWT.TOP | SWT.RIGHT);
  decoDeadline.setImage(errorImage);
  decoDeadline.hide();

  ModifyListener listener = new ModifyListener() {

    @Override
    public void modifyText(ModifyEvent e) {
      Button button = getButton(IDialogConstants.OK_ID);
      if (button != null) {
        button.setEnabled(verifyInput());
      }
    }
  };
  feeText.addModifyListener(listener);
  deadlineText.addModifyListener(listener);

  return container;
}
 
Example 11
Source File: QueryExpressionEditor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private void createQueryParametersTable(final Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(GridDataFactory.fillDefaults().span(2, 1).grab(true, true).create());
    composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 2).create());

    final Label parameterLabel = new Label(composite, SWT.NONE);
    parameterLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).create());
    parameterLabel.setText(Messages.parameters);

    final ControlDecoration parameterDecoration = new ControlDecoration(parameterLabel, SWT.RIGHT);
    parameterDecoration.setShowOnlyOnFocus(false);
    parameterDecoration.setDescriptionText(Messages.paginationParameterHint);
    parameterDecoration.setImage(Pics.getImage(PicsConstants.hint));
    parameterDecoration.hide();
    observeQuerySingleSelection.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(final ValueChangeEvent event) {
            final Object newValue = event.diff.getNewValue();
            if (newValue instanceof Expression) {
                if (List.class.getName().equals(((Expression) newValue).getReturnType())) {
                    parameterDecoration.show();
                } else {
                    parameterDecoration.hide();
                }
            }

        }
    });

    final TableViewer parametersTableViewer = new TableViewer(composite,
            SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL);
    parametersTableViewer.getControl()
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 80).create());
    parametersTableViewer.getTable().setLinesVisible(true);
    parametersTableViewer.getTable().setHeaderVisible(true);
    parametersTableViewer.setContentProvider(new ObservableListContentProvider());

    queryParameterObserveDetailList = EMFObservables.observeDetailList(Realm.getDefault(),
            observeQuerySingleSelection,
            ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS);

    final TableLayout tableLayout = new TableLayout();
    tableLayout.addColumnData(new ColumnWeightData(1, true));
    tableLayout.addColumnData(new ColumnWeightData(1, true));
    parametersTableViewer.getTable().setLayout(tableLayout);

    createNameColumn(parametersTableViewer);
    createValueColumn(parametersTableViewer);

    parametersTableViewer.setInput(queryParameterObserveDetailList);
}
 
Example 12
Source File: ExpressionViewer.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected void createTextControl(final int style, final TabbedPropertySheetWidgetFactory widgetFactory) {
    if (expressionProposalLableProvider == null) {
        expressionProposalLableProvider = new ExpressionLabelProvider();
    }
    contentAssistText = new ContentAssistText(control, expressionProposalLableProvider, style);

    textControl = contentAssistText.getTextControl();
    if (widgetFactory != null) {
        widgetFactory.adapt(textControl, false, false);
    }
    textControl.addDisposeListener(disposeListener);
    textTooltip = new DefaultToolTip(textControl) {

        @Override
        protected boolean shouldCreateToolTip(final Event event) {
            return super.shouldCreateToolTip(event) && getText(event) != null;
        }
    };
    textTooltip.setShift(new Point(5, 5));
    textTooltip.setRespectMonitorBounds(true);
    textTooltip.setPopupDelay(100);

    typeDecoration = new ControlDecoration(contentAssistText.getToolbar(), SWT.LEFT, control);
    typeDecoration.setMarginWidth(0);

    messageDecoration = new ControlDecoration(contentAssistText, SWT.LEFT, control);
    messageDecoration.setShowHover(true);
    messageDecoration.setMarginWidth(1);
    messageDecoration.hide();

    contentAssistText.addContentAssistListener(this);
    autoCompletion = contentAssistText.getAutocompletion();
    autoCompletion.addExpressionProposalListener(this);

    int indent = 0;
    if ((style & SWT.PASSWORD) != 0) {
        isPassword = true;
    }
    if ((style & SWT.BORDER) != 0) {
        indent = 16;
    }
    contentAssistText.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).indent(indent, 0)
            .grab(true, false).create());
}
 
Example 13
Source File: AliasControl.java    From offspring with MIT License 4 votes vote down vote up
public AliasControl(Composite parent, int style, Long accountId,
    INxtService nxt, IStylingEngine engine, IUserService userService,
    UISynchronize sync, IContactsService contactsService) {
  super(parent, style);
  this.accountId = accountId;
  this.nxt = nxt;
  this.user = userService.findUser(accountId);
  this.sync = sync;
  this.contactsService = contactsService;
  GridLayoutFactory.fillDefaults().spacing(10, 5).numColumns(3).applyTo(this);

  /* top bar (name, uri, register) */

  if (user != null && !user.getAccount().isReadOnly()) {
    aliasNameText = new Text(this, SWT.BORDER);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER)
        .hint(100, SWT.DEFAULT).applyTo(aliasNameText);
    aliasNameText.setMessage("name");

    decoAliasNameText = new ControlDecoration(aliasNameText, SWT.TOP
        | SWT.RIGHT);
    decoAliasNameText.setImage(errorImage);
    decoAliasNameText.setDescriptionText("Alias is registered");
    decoAliasNameText.hide();

    aliasURIText = new Text(this, SWT.BORDER);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER)
        .grab(true, false).applyTo(aliasURIText);
    aliasURIText.setMessage("uri");

    aliasRegisterButton = new Button(this, SWT.PUSH);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER)
        .applyTo(aliasRegisterButton);

    aliasRegisterButton.setText("Register");
    aliasRegisterButton.setEnabled(false);

    hookupAliasControls();
  }

  /* bottom bar table viewer */

  paginationContainer = new PaginationContainer(this, SWT.NONE);
  GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true)
      .span(3, 1).applyTo(paginationContainer);

  aliasesViewer = new AliasViewer(paginationContainer.getViewerParent(),
      accountId, nxt, engine, userService, sync, contactsService);
  paginationContainer.setTableViewer(aliasesViewer, 100);

  aliasesViewer.addSelectionChangedListener(new ISelectionChangedListener() {

    @Override
    public void selectionChanged(SelectionChangedEvent event) {}
  });
}
 
Example 14
Source File: TextVarWarning.java    From hop with Apache License 2.0 4 votes vote down vote up
public TextVarWarning( IVariables variables, Composite composite, int flags ) {
  super( composite, SWT.NONE );

  warningInterfaces = new ArrayList<IWarning>();

  FormLayout formLayout = new FormLayout();
  formLayout.marginWidth = 0;
  formLayout.marginHeight = 0;
  formLayout.marginTop = 0;
  formLayout.marginBottom = 0;

  this.setLayout( formLayout );

  // add a text field on it...
  wText = new TextVar( variables, this, flags );

  warningControlDecoration = new ControlDecoration( wText, SWT.CENTER | SWT.RIGHT );
  Image warningImage = GuiResource.getInstance().getImageWarning();
  warningControlDecoration.setImage( warningImage );
  warningControlDecoration.setDescriptionText( BaseMessages.getString( PKG, "TextVar.tooltip.FieldIsInUse" ) );
  warningControlDecoration.hide();

  // If something has changed, check the warning interfaces
  //
  wText.addModifyListener( new ModifyListener() {
    public void modifyText( ModifyEvent arg0 ) {

      // Verify all the warning interfaces.
      // Show the first that has a warning to show...
      //
      boolean foundOne = false;
      for ( IWarning warningInterface : warningInterfaces ) {
        IWarningMessage warningSituation =
          warningInterface.getWarningSituation( wText.getText(), wText, this );
        if ( warningSituation.isWarning() ) {
          foundOne = true;
          warningControlDecoration.show();
          warningControlDecoration.setDescriptionText( warningSituation.getWarningMessage() );
          break;
        }
      }
      if ( !foundOne ) {
        warningControlDecoration.hide();
      }
    }
  } );

  FormData fdText = new FormData();
  fdText.top = new FormAttachment( 0, 0 );
  fdText.left = new FormAttachment( 0, 0 );
  fdText.right = new FormAttachment( 100, -warningImage.getBounds().width );
  wText.setLayoutData( fdText );
}
 
Example 15
Source File: WarningText.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public WarningText( Composite composite, int flags ) {
  super( composite, SWT.NONE );

  warningInterfaces = new ArrayList<WarningInterface>();

  FormLayout formLayout = new FormLayout();
  formLayout.marginWidth = 0;
  formLayout.marginHeight = 0;
  formLayout.marginTop = 0;
  formLayout.marginBottom = 0;

  this.setLayout( formLayout );

  // add a text field on it...
  wText = new Text( this, flags );

  warningControlDecoration = new ControlDecoration( wText, SWT.CENTER | SWT.RIGHT );
  Image warningImage = GUIResource.getInstance().getImageWarning();
  warningControlDecoration.setImage( warningImage );
  warningControlDecoration.setDescriptionText( BaseMessages.getString( PKG, "TextVar.tooltip.FieldIsInUse" ) );
  warningControlDecoration.hide();

  // If something has changed, check the warning interfaces
  //
  wText.addModifyListener( new ModifyListener() {
    public void modifyText( ModifyEvent arg0 ) {

      // Verify all the warning interfaces.
      // Show the first that has a warning to show...
      //
      boolean foundOne = false;
      for ( WarningInterface warningInterface : warningInterfaces ) {
        WarningMessageInterface warningSituation =
          warningInterface.getWarningSituation( wText.getText(), wText, this );
        if ( warningSituation.isWarning() ) {
          foundOne = true;
          warningControlDecoration.show();
          warningControlDecoration.setDescriptionText( warningSituation.getWarningMessage() );
          break;
        }
      }
      if ( !foundOne ) {
        warningControlDecoration.hide();
      }
    }
  } );

  FormData fdText = new FormData();
  fdText.top = new FormAttachment( 0, 0 );
  fdText.left = new FormAttachment( 0, 0 );
  fdText.right = new FormAttachment( 100, -warningImage.getBounds().width );
  wText.setLayoutData( fdText );
}
 
Example 16
Source File: JSLintValidatorPreferenceCompositeFactory.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public Composite createPreferenceComposite(Composite parent, final IBuildParticipantWorkingCopy participant)
{
	Composite master = new Composite(parent, SWT.NONE);
	master.setLayout(GridLayoutFactory.fillDefaults().create());

	GridDataFactory fillHoriz = GridDataFactory.fillDefaults().grab(true, false);

	// JSON Options
	Group group = new Group(master, SWT.BORDER);
	group.setText(Messages.JSLintValidatorPreferenceCompositeFactory_OptionsTitle);
	group.setLayout(new GridLayout());
	group.setLayoutData(fillHoriz.create());

	Label label = new Label(group, SWT.WRAP);
	label.setText(Messages.JSLintValidatorPreferenceCompositeFactory_OptionsMsg);
	fillHoriz.applyTo(label);

	final Text text = new Text(group, SWT.MULTI | SWT.V_SCROLL);

	final ControlDecoration decoration = new ControlDecoration(text, SWT.LEFT | SWT.TOP);
	decoration.setDescriptionText(Messages.JSLintValidatorPreferenceCompositeFactory_OptionsParseError);
	decoration.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_DEC_FIELD_ERROR));
	decoration.hide();

	text.setText(participant.getPreferenceString(IPreferenceConstants.JS_LINT_OPTIONS));
	fillHoriz.hint(SWT.DEFAULT, 100).applyTo(text);
	text.addModifyListener(new ModifyListener()
	{
		public void modifyText(ModifyEvent e)
		{
			decoration.hide();
			try
			{
				String optionsAsJSON = text.getText();
				JSON.parse(optionsAsJSON);
				participant.setPreference(IPreferenceConstants.JS_LINT_OPTIONS, text.getText());
			}
			catch (IllegalStateException e1)
			{
				decoration.show();
			}
		}
	});

	// Filters
	Composite filtersGroup = new ValidatorFiltersPreferenceComposite(master, participant);
	filtersGroup.setLayoutData(fillHoriz.grab(true, true).hint(SWT.DEFAULT, 150).create());

	return master;
}
 
Example 17
Source File: TextVarWarning.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public TextVarWarning( VariableSpace space, Composite composite, int flags ) {
  super( composite, SWT.NONE );

  warningInterfaces = new ArrayList<WarningInterface>();

  FormLayout formLayout = new FormLayout();
  formLayout.marginWidth = 0;
  formLayout.marginHeight = 0;
  formLayout.marginTop = 0;
  formLayout.marginBottom = 0;

  this.setLayout( formLayout );

  // add a text field on it...
  wText = new TextVar( space, this, flags );

  warningControlDecoration = new ControlDecoration( wText, SWT.CENTER | SWT.RIGHT );
  Image warningImage = GUIResource.getInstance().getImageWarning();
  warningControlDecoration.setImage( warningImage );
  warningControlDecoration.setDescriptionText( BaseMessages.getString( PKG, "TextVar.tooltip.FieldIsInUse" ) );
  warningControlDecoration.hide();

  // If something has changed, check the warning interfaces
  //
  wText.addModifyListener( new ModifyListener() {
    public void modifyText( ModifyEvent arg0 ) {

      // Verify all the warning interfaces.
      // Show the first that has a warning to show...
      //
      boolean foundOne = false;
      for ( WarningInterface warningInterface : warningInterfaces ) {
        WarningMessageInterface warningSituation =
          warningInterface.getWarningSituation( wText.getText(), wText, this );
        if ( warningSituation.isWarning() ) {
          foundOne = true;
          warningControlDecoration.show();
          warningControlDecoration.setDescriptionText( warningSituation.getWarningMessage() );
          break;
        }
      }
      if ( !foundOne ) {
        warningControlDecoration.hide();
      }
    }
  } );

  FormData fdText = new FormData();
  fdText.top = new FormAttachment( 0, 0 );
  fdText.left = new FormAttachment( 0, 0 );
  fdText.right = new FormAttachment( 100, -warningImage.getBounds().width );
  wText.setLayoutData( fdText );
}
 
Example 18
Source File: SuffixText.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a decoration with the given image for this text.
 *
 * Note that the decoration is only displayed in focus.
 */
public void createDecoration(Image decorationImage) {
	contentProposalDecoration = new ControlDecoration(this, SWT.TOP | SWT.LEFT);
	contentProposalDecoration.setImage(decorationImage);
	contentProposalDecoration.hide();
}
 
Example 19
Source File: NodeAttachDebugTab.java    From wildwebdeveloper with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void createControl(Composite parent) {
	super.createControl(parent);
	Composite composite = (Composite)getControl();
	Composite rootMapComposite = new Composite(composite, SWT.NONE);
	GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).span(((GridLayout)composite.getLayout()).numColumns, 1).grab(true, false).indent(0, 40).applyTo(rootMapComposite);
	rootMapComposite.setLayout(new GridLayout(3, false));
	Label rootMapDescription = new Label(rootMapComposite, SWT.NONE);
	rootMapDescription.setText(Messages.NodeAttach_rootMapDescription);
	rootMapDescription.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 3, 1));
	GridDataFactory indentFactory = GridDataFactory.swtDefaults().indent(20, 0);
	Label remoteRootLabel = new Label(rootMapComposite, SWT.NONE);
	remoteRootLabel.setText(Messages.NodeAttach_remoteRoot);
	indentFactory.applyTo(remoteRootLabel);
	remoteRootText = new Text(rootMapComposite, SWT.BORDER);
	remoteRootText.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1));
	remoteRootText.addModifyListener(e -> {
		setDirty(true);
		updateLaunchConfigurationDialog();
	});
	Label localRootLabel = new Label(rootMapComposite, SWT.NONE);
	localRootLabel.setText(Messages.NodeAttach_localRoot);
	indentFactory.applyTo(localRootLabel);
	localRootText = new Text(rootMapComposite, SWT.BORDER);
	localRootText.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
	Button browseLocalButton = new Button(rootMapComposite, SWT.PUSH);
	browseLocalButton.setText(Messages.AbstractRunHTMLDebugTab_browse);
	browseLocalButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
		DirectoryDialog directoryDialog = new DirectoryDialog(browseLocalButton.getShell());
		directoryDialog.setText(Messages.NodeAttach_localRoot);
		String selectedDirString = directoryDialog.open();
		if (selectedDirString != null) {
			localRootText.setText(selectedDirString);
		}
	}));
	ControlDecoration invalidDirectoryDecoration = new ControlDecoration(localRootText, SWT.TOP | SWT.LEFT);
	invalidDirectoryDecoration.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_WARNING).getImage());
	invalidDirectoryDecoration.setDescriptionText(Messages.NodeAttach_invalidLocalRootDirectory);
	invalidDirectoryDecoration.hide();
	localRootText.addModifyListener(e -> {
		if (!localRootText.getText().isEmpty() && !new File(localRootText.getText()).isDirectory()) {
			invalidDirectoryDecoration.show();
			setWarningMessage(Messages.NodeAttach_invalidLocalRootDirectory);
		} else {
			invalidDirectoryDecoration.hide();
			setWarningMessage(null);
		}
		setDirty(true);
		updateLaunchConfigurationDialog();
	});
}
 
Example 20
Source File: WarningText.java    From hop with Apache License 2.0 4 votes vote down vote up
public WarningText( Composite composite, int flags ) {
  super( composite, SWT.NONE );

  warningInterfaces = new ArrayList<IWarning>();

  FormLayout formLayout = new FormLayout();
  formLayout.marginWidth = 0;
  formLayout.marginHeight = 0;
  formLayout.marginTop = 0;
  formLayout.marginBottom = 0;

  this.setLayout( formLayout );

  // add a text field on it...
  wText = new Text( this, flags );

  warningControlDecoration = new ControlDecoration( wText, SWT.CENTER | SWT.RIGHT );
  Image warningImage = GuiResource.getInstance().getImageWarning();
  warningControlDecoration.setImage( warningImage );
  warningControlDecoration.setDescriptionText( BaseMessages.getString( PKG, "TextVar.tooltip.FieldIsInUse" ) );
  warningControlDecoration.hide();

  // If something has changed, check the warning interfaces
  //
  wText.addModifyListener( new ModifyListener() {
    public void modifyText( ModifyEvent arg0 ) {

      // Verify all the warning interfaces.
      // Show the first that has a warning to show...
      //
      boolean foundOne = false;
      for ( IWarning warningInterface : warningInterfaces ) {
        IWarningMessage warningSituation =
          warningInterface.getWarningSituation( wText.getText(), wText, this );
        if ( warningSituation.isWarning() ) {
          foundOne = true;
          warningControlDecoration.show();
          warningControlDecoration.setDescriptionText( warningSituation.getWarningMessage() );
          break;
        }
      }
      if ( !foundOne ) {
        warningControlDecoration.hide();
      }
    }
  } );

  FormData fdText = new FormData();
  fdText.top = new FormAttachment( 0, 0 );
  fdText.left = new FormAttachment( 0, 0 );
  fdText.right = new FormAttachment( 100, -warningImage.getBounds().width );
  wText.setLayoutData( fdText );
}