Java Code Examples for org.eclipse.swt.widgets.Label#setVisible()

The following examples show how to use org.eclipse.swt.widgets.Label#setVisible() . 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: 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 2
Source File: RadioGroupFieldEditor.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public void setVisible(boolean visible, Composite parent) {
    if (!useGroup) {
        Label labelControl = getLabelControl(parent);
        labelControl.setVisible(visible);
        Object layoutData = labelControl.getLayoutData();
        if (layoutData instanceof GridData) {
            ((GridData) layoutData).exclude = !visible;
        }

        radioBox.setVisible(visible);
        layoutData = radioBox.getLayoutData();
        if (layoutData instanceof GridData) {
            ((GridData) layoutData).exclude = !visible;
        }
    } else {
        // TODO: Implement when needed.
    }

}
 
Example 3
Source File: CustomStringFieldEditor.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public void setVisible(boolean visible, Composite parent) {
    Label labelControl = getLabelControl(parent);
    Text textControl = getTextControl(parent);
    labelControl.setVisible(visible);
    textControl.setVisible(visible);

    Object layoutData = labelControl.getLayoutData();
    if (layoutData instanceof GridData) {
        ((GridData) layoutData).exclude = !visible;
    }
    layoutData = textControl.getLayoutData();
    if (layoutData instanceof GridData) {
        ((GridData) layoutData).exclude = !visible;
    }

}
 
Example 4
Source File: JavaSearchPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Control createSearchFor(Composite parent) {
	Group result= new Group(parent, SWT.NONE);
	result.setText(SearchMessages.SearchPage_searchFor_label);
	result.setLayout(new GridLayout(2, true));

	fSearchFor= new Button[] {
		createButton(result, SWT.RADIO, SearchMessages.SearchPage_searchFor_type, TYPE, true),
		createButton(result, SWT.RADIO, SearchMessages.SearchPage_searchFor_method, METHOD, false),
		createButton(result, SWT.RADIO, SearchMessages.SearchPage_searchFor_package, PACKAGE, false),
		createButton(result, SWT.RADIO, SearchMessages.SearchPage_searchFor_constructor, CONSTRUCTOR, false),
		createButton(result, SWT.RADIO, SearchMessages.SearchPage_searchFor_field, FIELD, false)
	};

	// Fill with dummy radio buttons
	Label filler= new Label(result, SWT.NONE);
	filler.setVisible(false);
	filler.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));

	return result;
}
 
Example 5
Source File: GroupOrWrap.java    From Rel with Apache License 2.0 6 votes vote down vote up
private void addRowAllButAndAs(Composite parent, boolean selected, String astext) {
	Label lblNewLabel = new Label(parent, SWT.NONE);
	lblNewLabel.setText("ALL BUT");

	checkAllBut = new Button(parent, SWT.CHECK);
	checkAllBut.setSelection(selected);

	Label dummy = new Label(parent, SWT.NONE);
	dummy.setVisible(false);

	Label asPrompt = new Label(parent, SWT.NONE);
	asPrompt.setAlignment(SWT.RIGHT);
	asPrompt.setText("As:");

	as = new Text(parent, SWT.NONE);
	as.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
	as.setText(astext);
}
 
Example 6
Source File: ListDialogField.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private Label createSeparator(Composite parent) {
	Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
	separator.setFont(parent.getFont());
	separator.setVisible(false);
	GridData gd = new GridData();
	gd.horizontalAlignment = GridData.FILL;
	gd.verticalAlignment = GridData.BEGINNING;
	gd.verticalIndent = 4;
	separator.setLayoutData(gd);
	return separator;
}
 
Example 7
Source File: TreeListDialogField.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private Label createSeparator(Composite parent) {
	Label separator= new Label(parent, SWT.NONE);
	separator.setFont(parent.getFont());
	separator.setVisible(false);
	GridData gd= new GridData();
	gd.horizontalAlignment= GridData.FILL;
	gd.verticalAlignment= GridData.BEGINNING;
	gd.heightHint= 4;
	separator.setLayoutData(gd);
	return separator;
}
 
Example 8
Source File: PropertyHandleTableViewer.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void createSeparator( Composite parent )
{
	Label separator = new Label( parent, SWT.SEPARATOR | SWT.HORIZONTAL );
	separator.setVisible( false );
	GridData gd = new GridData( );
	gd.verticalIndent = 20;
	separator.setLayoutData( gd );
}
 
Example 9
Source File: ChartCubeFilterConditionBuilder.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private int create2ValueComposite( Composite condition )
{

	if ( expressionValue1 != null && !expressionValue1.isDisposed( ) )
	{
		return 0;
	}

	if ( valueListComposite != null && !valueListComposite.isDisposed( ) )
	{
		valueListComposite.dispose( );
		valueListComposite = null;
	}

	GridData expgd = new GridData( );
	expgd.widthHint = 100;

	expressionValue1 = createExpressionValue( condition );
	expressionValue1.setLayoutData( expgd );

	dummy1 = createDummy( condition, 3 );

	andLable = new Label( condition, SWT.NONE );
	andLable.setText( Messages.getString( "FilterConditionBuilder.text.AND" ) ); //$NON-NLS-1$
	andLable.setEnabled( false );
	andLable.setVisible( false );

	dummy2 = createDummy( condition, 3 );

	expressionValue2 = createExpressionValue( condition );
	expressionValue2.setLayoutData( expgd );

	expressionValue2.setVisible( false );
	ExpressionButtonUtil.getExpressionButton( expressionValue2 )
			.getControl( )
			.setVisible( false );

	condition.getParent( ).layout( true, true );
	return 1;
}
 
Example 10
Source File: AttributeListPanel.java    From Rel with Apache License 2.0 5 votes vote down vote up
private void addRowAllBut(boolean selected) {
	Label lblNewLabel = new Label(this, SWT.NONE);
	lblNewLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
	lblNewLabel.setText("ALL BUT");

	checkAllBut = new Button(this, SWT.CHECK);
	checkAllBut.setSelection(selected);

	Label dummy = new Label(this, SWT.NONE);
	dummy.setVisible(false);
}
 
Example 11
Source File: TreeListDialogField.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Label createSeparator(Composite parent) {
	Label separator= new Label(parent, SWT.NONE);
	separator.setFont(parent.getFont());
	separator.setVisible(false);
	GridData gd= new GridData();
	gd.horizontalAlignment= GridData.FILL;
	gd.verticalAlignment= GridData.BEGINNING;
	gd.heightHint= 4;
	separator.setLayoutData(gd);
	return separator;
}
 
Example 12
Source File: NetworkPreferencePage.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private Group createUpnpGroup(Composite parent) {

    Group group = new Group(parent, SWT.NONE);
    group.setText(Messages.NetworkPreferencePage_upnp_devices);

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;

    group.setLayout(gridLayout);
    group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));

    gatewayInfo = new Label(group, SWT.CENTER);
    gatewayInfo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    upnpDevicesTable = new Table(group, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION);

    upnpDevicesTable.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    upnpDevicesTable.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            if (event.detail == SWT.CHECK) handleGatewaySelection(event);
          }
        });

    gatewayInfo.setVisible(false);
    upnpDevicesTable.setVisible(false);

    return group;
  }
 
Example 13
Source File: AddAnalysisDialog.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
protected void setErrorLabel(Label label, String errorMessage) {
    if (label != null && !label.isDisposed()) {
        label.setText(errorMessage == null ? " \n " : errorMessage); //$NON-NLS-1$
        final boolean hasError = errorMessage != null && (StringConverter.removeWhiteSpaces(errorMessage)).length() > 0;
        label.setEnabled(hasError);
        label.setVisible(hasError);
        label.getParent().update();
        Control button = getButton(IDialogConstants.OK_ID);

        if (button != null) {
            button.setEnabled(errorMessage == null);
        }
    }
}
 
Example 14
Source File: MessageDialogWithPrompt.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Control createCustomArea(Composite parent) {
    if (detailsMessage != null) {
        parent.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());
        //Above Image filler
        Image image = getImage();
        if (image != null) {
            Label filler = new Label(parent, SWT.NULL);
            filler.setImage(image);
            GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING)
                    .applyTo(filler);
            filler.setVisible(false);
        }

        Section section = new Section(parent,
                Section.TWISTIE | Section.NO_TITLE_FOCUS_BOX | Section.CLIENT_INDENT);
        section.setText(Messages.moreDetails);
        section.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

        Composite client = new Composite(section, SWT.NONE);
        client.setLayoutData(GridDataFactory.fillDefaults().create());
        client.setLayout(GridLayoutFactory.fillDefaults().create());

        Link detailsLabel = new Link(client, getMessageLabelStyle());
        linkSelectionListener.ifPresent(listener -> detailsLabel.addListener(SWT.Selection, listener));
        detailsLabel.setText(detailsMessage);
        GridDataFactory
                .fillDefaults()
                .align(SWT.FILL, SWT.BEGINNING)
                .grab(true, false)
                .hint(convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH),
                        SWT.DEFAULT)
                .applyTo(detailsLabel);
        section.setClient(client);
        section.addExpansionListener(new ExpansionAdapter() {

            @Override
            public void expansionStateChanged(ExpansionEvent e) {
                parent.getShell().pack();
            }
        });
        return section;
    }
    return super.createCustomArea(parent);
}
 
Example 15
Source File: CodeAssistAdvancedConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void createFiller(Composite composite, int h_span) {
   Label filler= new Label(composite, SWT.NONE);
filler.setVisible(false);
filler.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, h_span, 1));
  }
 
Example 16
Source File: AddFeatureDialog.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Create contents of the dialog.
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
	Composite container = (Composite) super.createDialogArea(parent);
	container.setLayout(new GridLayout(1, false));
	tabFolder = new TabFolder(container, SWT.NONE);
	tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	
	TabItem ui_LayoutItem = new TabItem(tabFolder, SWT.NONE);
	ui_LayoutItem.setText(Messages.AddFeatureDialog_UI);
	TableViewer UIViewer = createTable(tabFolder, ui_LayoutItem);
	UIViewer.setInput(getFeatureByType(Messages.AddFeatureDialog_THREE));
	
	TabItem navigationMenuItem = new TabItem(tabFolder, SWT.NONE);
	navigationMenuItem.setText(Messages.AddFeatureDialog_VIDEO);
	TableViewer videoViewer = createTable(tabFolder, navigationMenuItem);
	videoViewer.setInput(getFeatureByType(Messages.AddFeatureDialog_FOUR));
	
	TabItem extendedItem = new TabItem(tabFolder, SWT.NONE);
	extendedItem.setText(Messages.AddFeatureDialog_3RD);
	TableViewer _3rdItemViewer = createTable(tabFolder, extendedItem);
	_3rdItemViewer.setInput(getFeatureByType(Messages.AddFeatureDialog_FIVE));
	
	TabItem open_sdk_Item = new TabItem(tabFolder, SWT.NONE);
	open_sdk_Item.setText(Messages.AddFeatureDialog_CUSTOM);
	TableViewer customViewer = createTable(tabFolder, open_sdk_Item);
	customViewer.setInput(getFeatureByType(Messages.AddFeatureDialog_EIGHT));
	
	TabItem deviceAccessItem = new TabItem(tabFolder, SWT.NONE);
	deviceAccessItem.setText(Messages.AddFeatureDialog_INTERACTION);
	TableViewer InteractionViewer = createTable(tabFolder, deviceAccessItem);
	InteractionViewer.setInput(getFeatureByType(Messages.AddFeatureDialog_TWO));
	
	TabItem cloud_ServerItem = new TabItem(tabFolder, SWT.NONE);
	cloud_ServerItem.setText(Messages.AddFeatureDialog_CLOUDSERVER);
	TableViewer cloud_ServerViewer = createTable(tabFolder, cloud_ServerItem);
	cloud_ServerViewer.setInput(getFeatureByType(Messages.AddFeatureDialog_NINE));
	 
	Composite composite = new Composite(container, SWT.NONE);
	composite.setLayout(new GridLayout(4, false));
	composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
	
	lblParamkey = new Label(composite, SWT.NONE);
	lblParamkey.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
	lblParamkey.setText("       urlScheme");
	lblParamkey.setVisible(false);
	
	text_urlScheme = new Text(composite, SWT.BORDER);
	text_urlScheme.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
	text_urlScheme.setVisible(false);
	
	lblParamvalue = new Label(composite, SWT.NONE);
	lblParamvalue.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
	lblParamvalue.setText("     apiKey");
	lblParamvalue.setVisible(false);
	
	text_apiKey = new Text(composite, SWT.BORDER);
	text_apiKey.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
	text_apiKey.setVisible(false);
	return container;
}
 
Example 17
Source File: SaveScreen.java    From AndroidRobot with Apache License 2.0 4 votes vote down vote up
/**
 * Create contents of the dialog.
 */
private void createContents() {
    shell = new Shell(getParent(), getStyle());
    shell.setSize(450, 415);
    shell.setText(getText());
    shell.setImage(SWTResourceManager.getImage(".\\icons\\title.png"));
    shell.setLayout(new GridLayout(1, false));
    display = getParent().getDisplay();

    Composite composite1 = new Composite(shell, SWT.NONE);
    GridData gd_composite1 = new GridData(435, 50);
    gd_composite1.verticalAlignment = SWT.CENTER;
    composite1.setLayoutData(gd_composite1);
    composite1.setLayout(new GridLayout(3, false));

    Label lbNewScript = new Label(composite1, SWT.CENTER);
    lbNewScript.setText("保存截图");
    lbNewScript.setFont(new Font(display, "宋体", 12, SWT.BOLD));
    new Label(composite1, SWT.NONE);
    new Label(composite1, SWT.NONE);

    lblError = new Label(composite1, SWT.NONE);
    GridData gd_lblError = new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1);
    gd_lblError.widthHint = 207;
    lblError.setLayoutData(gd_lblError);
    lblError.setText("New Label");
    lblError.setVisible(false);
    /*
    Label abc1 = new Label(composite1,SWT.CENTER);
    abc1.setText("                                                                         ");
    abc1.setVisible(false);
    Label abc2 = new Label(composite1,SWT.CENTER);
    FileInputStream input;
    try {
    	input = new FileInputStream(new File(
    			".\\icons\\title.png"));
    	ImageData imageData = new ImageData(input);
    	abc2.setImage(new Image(Display.getDefault(), imageData));
    } catch (FileNotFoundException e) {
    	// TODO Auto-generated catch block
    	e.printStackTrace();
    }
    */

}
 
Example 18
Source File: TopicSelection.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void layoutUI() {
  FormLayout topicSelectionLayout = new FormLayout();
  this.setLayout( topicSelectionLayout );

  wTopicGroup = new Group( this, SWT.SHADOW_ETCHED_IN );
  props.setLook( wTopicGroup );
  wTopicGroup.setText( topicGroupLabel );

  FormLayout topicGroupLayout = new FormLayout();
  topicGroupLayout.marginHeight = 15;
  topicGroupLayout.marginWidth = 15;
  wTopicGroup.setLayout( topicGroupLayout );

  wTopicGroup.setLayoutData( new FormDataBuilder().top( 0, ConstUI.MEDUIM_MARGIN ).fullWidth().bottom().result() );

  wTopicFromText = new Button( wTopicGroup, SWT.RADIO );
  wTopicFromField = new Button( wTopicGroup, SWT.RADIO );
  props.setLook( wTopicFromText );
  props.setLook( wTopicFromField );

  SelectionAdapter selectionListener = new SelectionAdapter() {
    @Override
    public void widgetSelected( SelectionEvent selectionEvent ) {
      super.widgetSelected( selectionEvent );
      setTopicWidgetVisibility( wTopicFromField );
    }
  };

  wTopicFromField.addSelectionListener( selectionListener );
  wTopicFromText.addSelectionListener( selectionListener );

  wTopicFromField.setSelection( topicInField );
  wTopicFromText.setSelection( !topicInField );

  wTopicFromText.setText( textTopicRadioLabel );
  wTopicFromField.setText( fieldTopicRadioLabel );

  wTopicFromText.setLayoutData( new FormDataBuilder().left().top().result() );

  wTopicFromField.setLayoutData( new FormDataBuilder().left().top( wTopicFromText ).result() );
  wTopicFromField.addSelectionListener( selectionListener );
  wTopicFromText.addSelectionListener( selectionListener );

  Label separator = new Label( wTopicGroup, SWT.SEPARATOR | SWT.VERTICAL );
  separator.setLayoutData( new FormDataBuilder().top().left( wTopicFromField, 15 ).bottom().result() );

  wlTopic = new Label( wTopicGroup, SWT.LEFT );
  props.setLook( wlTopic );

  if ( displayTopicErrorIcon ) {
    //Connection Error Icon label
    wlTopic.setLayoutData( new FormDataBuilder().top().left( separator, 15 ).result() );

    wlConnectionError = new Label( wTopicGroup, SWT.LEFT );
    wlConnectionError.setToolTipText( fieldTopicErrorToolTip );
    wlConnectionError.setImage( SwtSvgImageUtil.getImage(
      this.getDisplay(), getClass().getClassLoader(), "error.svg", ConstUI.SMALL_ICON_SIZE,
      ConstUI.SMALL_ICON_SIZE ) );
    props.setLook( wlConnectionError );

    wlConnectionError.setLayoutData( new FormDataBuilder().top().left( wlTopic, MARGIN ).result() );
    wlConnectionError.setVisible( false );
  } else {
    wlTopic.setLayoutData( new FormDataBuilder().top().left( separator, 15 ).right().result() );
  }

  FormData fdTopic = new FormDataBuilder().top( wlTopic ).left( separator, 15 ).right().result();

  wTopicTextCombo = new ComboVar( transMeta, wTopicGroup, SWT.SINGLE | SWT.LEFT | SWT.BORDER );
  props.setLook( wTopicTextCombo );
  wTopicTextCombo.setLayoutData( fdTopic );
  wTopicTextCombo.addModifyListener( lsMod );

  wTopicText = new TextVar( transMeta, wTopicGroup, SWT.SINGLE | SWT.LEFT | SWT.BORDER );
  props.setLook( wTopicText );
  wTopicText.setLayoutData( fdTopic );
  wTopicText.addModifyListener( lsMod );

  wTopicField = createFieldDropDown( wTopicGroup, props, stepMeta, fdTopic );
  props.setLook( wTopicField );
  wTopicField.setLayoutData( fdTopic );
  setTopicWidgetVisibility( wTopicFromField );
  wTopicField.addModifyListener( lsMod );
}
 
Example 19
Source File: NewScript.java    From AndroidRobot with Apache License 2.0 4 votes vote down vote up
/**
 * Create contents of the dialog.
 */
private void createContents() {
	shell = new Shell(getParent(), getStyle());
	shell.setSize(450, 300);
	shell.setText(getText());
	shell.setImage(SWTResourceManager.getImage(".\\icons\\title.png"));
	shell.setLayout(new GridLayout(1,false));
	display = getParent().getDisplay();
	 
	Composite composite1 = new Composite(shell, SWT.NONE);
	GridData gd_composite1 = new GridData(435, 50);
	gd_composite1.verticalAlignment = SWT.CENTER;
	composite1.setLayoutData(gd_composite1);
	composite1.setLayout(new GridLayout(3,false));
	
	Label lbNewScript = new Label(composite1,SWT.CENTER);
	lbNewScript.setText("新建脚本框");
	lbNewScript.setFont(new Font(display,"宋体",12,SWT.BOLD));
	new Label(composite1, SWT.NONE);
	new Label(composite1, SWT.NONE);
	
	lblError = new Label(composite1, SWT.NONE);
	GridData gd_lblError = new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1);
	gd_lblError.widthHint = 207;
	lblError.setLayoutData(gd_lblError);
	lblError.setText("New Label");
	lblError.setVisible(false);
       /*
	Label abc1 = new Label(composite1,SWT.CENTER);
	abc1.setText("                                                                         ");
	abc1.setVisible(false);
	Label abc2 = new Label(composite1,SWT.CENTER);
	FileInputStream input;
	try {
		input = new FileInputStream(new File(
				".\\icons\\title.png"));
		ImageData imageData = new ImageData(input);
		abc2.setImage(new Image(Display.getDefault(), imageData));
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
       */
	

}
 
Example 20
Source File: ConfigurationSettingsWizardPage.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Setups gateway SWT controls by populating a gateway combobox and configuring an information
 * Label and the enabling checkbox.
 *
 * @param combo {@link Combo} selector to populate with discovered gateways
 * @param info {@link Label} displaying status information of the discovery
 * @param checkbox {@link Button} checkbox to enable/disable UPnP support
 */
private void populateGatewaySelectionControls(
    List<GatewayDevice> gateways, final Combo combo, final Label info, final Button checkbox) {

  combo.setEnabled(false);
  checkbox.setEnabled(false);
  combo.removeAll();

  // if no devices are found, return now - nothing to populate
  if (gateways == null || gateways.isEmpty()) {
    info.setText(Messages.UPnPUIUtils_no_gateway);
    info.getParent().pack();
    return;
  }

  this.gateways = new ArrayList<GatewayDevice>();

  // insert found gateways into combobox
  for (GatewayDevice gw : gateways) {
    try {
      String name = gw.getFriendlyName();
      if (!gw.isConnected()) name += Messages.UPnPUIUtils_disconnected;

      combo.add(name);
      this.gateways.add(gw);

    } catch (Exception e) {
      log.debug("Error updating UPnP selector:" + e.getMessage()); // $NON-NLS-1$
      // ignore faulty gateway
    }
  }

  // if valid gateway found, show info and enable
  if (combo.getItemCount() > 0) {
    checkbox.setEnabled(true);
    combo.setEnabled(true);
    combo.select(0);
    combo.pack();
    info.setVisible(false);
  } else {
    info.setText(Messages.UPnPUIUtils_no_valid_gateway);
  }
  info.getParent().pack();
}