Java Code Examples for org.eclipse.jface.viewers.TableViewer#setInput()

The following examples show how to use org.eclipse.jface.viewers.TableViewer#setInput() . 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: ContractPropertySectionTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void should_bindAddChildButtonEnablement_convert_boolean_value() throws Exception {
    section.init(new WritableValue(aContract().build(), Contract.class));
    final Button button = new Button(parent, SWT.PUSH);
    final TableViewer inputsTableViewer = new TableViewer(parent);
    inputsTableViewer.setLabelProvider(new LabelProvider());
    inputsTableViewer.setContentProvider(ArrayContentProvider.getInstance());

    final ContractInput textParentInput = ProcessFactory.eINSTANCE.createContractInput();
    textParentInput.setType(ContractInputType.TEXT);
    final ContractInput complexParentInput = ProcessFactory.eINSTANCE.createContractInput();
    complexParentInput.setType(ContractInputType.COMPLEX);

    inputsTableViewer.setInput(Arrays.asList(textParentInput, complexParentInput));
    section.bindAddChildButtonEnablement(button, inputsTableViewer);
    assertThat(button.isEnabled()).isFalse();
    assertThat(inputsTableViewer.getSelection().isEmpty()).isTrue();
    inputsTableViewer.setSelection(new StructuredSelection(textParentInput));
    assertThat(button.isEnabled()).isFalse();
    assertThat(inputsTableViewer.getSelection().isEmpty()).isFalse();

    inputsTableViewer.setSelection(new StructuredSelection(complexParentInput));
    assertThat(button.isEnabled()).isTrue();
}
 
Example 2
Source File: SelectDependencyDialog.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected Control createDialogArea(final Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);

    dependenciesViewer = new TableViewer(composite, SWT.BORDER | SWT.V_SCROLL | SWT.READ_ONLY | SWT.MULTI);
    dependenciesViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    dependenciesViewer.setContentProvider(new ArrayContentProvider());
    dependenciesViewer.setLabelProvider(adapterLabelProvider);

    final List<EObject> input = new ArrayList<EObject>();
    for (final Expression e : filteredExpression) {
        final EList<EObject> referencedElements = e.getReferencedElements();
        if (!referencedElements.isEmpty()) {
            final EObject element = referencedElements.get(0);
            input.add(ExpressionHelper.createDependencyFromEObject(element));
        }
    }

    dependenciesViewer.setInput(input);
    return composite;
}
 
Example 3
Source File: ConstraintEditionControl.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void createConstraintsDefinitionViewer(AbstractBdmFormPage formPage, Composite parent) {
    constraintViewer = new TableViewer(parent,
            SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
    constraintViewer.getTable()
            .setLayoutData(GridDataFactory.fillDefaults().span(2, 1).grab(true, true).create());
    constraintViewer.getTable().setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, CONSTRAINTS_LIST_VIEWER_ID);
    formPage.getToolkit().adapt(constraintViewer.getTable());
    ColumnViewerToolTipSupport.enableFor(constraintViewer);
    constraintViewer.setUseHashlookup(true);
    constraintViewer.getTable().setHeaderVisible(true);
    constraintViewer.getTable().setLinesVisible(true);
    constraintViewer.addFilter(createSearchFilter());

    TableLayout layout = new TableLayout();
    layout.addColumnData(new ColumnWeightData(1, true));
    layout.addColumnData(new ColumnWeightData(1, true));
    constraintViewer.getTable().setLayout(layout);

    createConstraintnameColumn(constraintViewer);
    createAttributesColumn(constraintViewer);

    constraintViewer.setContentProvider(new ObservableListContentProvider());
    constraintViewer.setInput(constraintsObservable);
    selectedConstraintObservable = ViewerProperties.singleSelection(UniqueConstraint.class).observe(constraintViewer);
}
 
Example 4
Source File: SelectDataWizardPage.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public void createDocumentTableViewerComposite(final Composite parent, final DataBindingContext dbc) {
    documentTableViewerComposite = new Composite(parent, SWT.NONE);
    documentTableViewerComposite.setLayout(GridLayoutFactory.swtDefaults().create());
    documentTableViewerComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    final TableViewer documentTableViewer = new TableViewer(documentTableViewerComposite,
            SWT.BORDER | SWT.SINGLE | SWT.NO_FOCUS | SWT.H_SCROLL
                    | SWT.V_SCROLL);
    documentTableViewer.getTable()
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(200, 100).create());
    final ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    documentTableViewer.setContentProvider(contentProvider);
    documentTableViewer.setLabelProvider(new DocumentStyledLabelProvider());
    documentTableViewer.setInput(new WritableList(availableDocuments, ProcessPackage.Literals.DOCUMENT));
    final IViewerObservableValue observeSingleSelection = ViewersObservables
            .observeSingleSelection(documentTableViewer);
    dbc.bindValue(observeSingleSelection, selectedDataObservable,
            updateValueStrategy().withValidator(createDefaultValueAlreadyDefinedValidator()).create(), null);
    documentButton.addSelectionListener(createDocumentSelectionAdapter());
}
 
Example 5
Source File: SelectDataWizardPage.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public void createBusinessVariableTableViewerComposite(final Composite parent, final DataBindingContext dbc) {
    businessVariableTableViewerComposite = new Composite(parent, SWT.NONE);
    businessVariableTableViewerComposite.setLayout(GridLayoutFactory.swtDefaults().create());
    businessVariableTableViewerComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    final TableViewer businessDataTableViewer = new TableViewer(businessVariableTableViewerComposite,
            SWT.BORDER | SWT.SINGLE | SWT.NO_FOCUS | SWT.H_SCROLL
                    | SWT.V_SCROLL);
    businessDataTableViewer.getTable().setLayout(GridLayoutFactory.fillDefaults().create());
    businessDataTableViewer.getTable()
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(200, 100).create());
    final ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    businessDataTableViewer.setContentProvider(contentProvider);
    final IObservableSet knownElements = contentProvider.getKnownElements();
    final IObservableMap[] labelMaps = EMFObservables.observeMaps(knownElements,
            new EStructuralFeature[] { ProcessPackage.Literals.ELEMENT__NAME,
                    ProcessPackage.Literals.DATA__MULTIPLE,
                    ProcessPackage.Literals.JAVA_OBJECT_DATA__CLASS_NAME });
    businessDataTableViewer
            .setLabelProvider(new BusinessObjectDataStyledLabelProvider(businessObjectStore, labelMaps));
    businessDataTableViewer
            .setInput(new WritableList(availableBusinessData, ProcessPackage.Literals.BUSINESS_OBJECT_DATA));
    final IViewerObservableValue observeSingleSelection = ViewersObservables
            .observeSingleSelection(businessDataTableViewer);
    dbc.bindValue(observeSingleSelection, selectedDataObservable);
    businessVariableButton.addSelectionListener(createBusinessVariableSelectionAdapter());
}
 
Example 6
Source File: SelectRegistredTemplateDialog.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Control createCustomArea(Composite parent) {
    final Composite container = new Composite(parent, parent.getStyle());
    container.setLayout(new GridLayout(1, false));
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    final TableViewer templatesTreeViewer = new TableViewer(container, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    Table table = templatesTreeViewer.getTable();
    final GridData gdTable = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gdTable.minimumWidth = TABLE_MINIMUM_WIDTH;
    gdTable.minimumHeight = TABLE_MINIMUM_HEIGHT;
    table.setLayoutData(gdTable);
    templatesTreeViewer.setContentProvider(new CollectionContentProvider());
    templatesTreeViewer.setLabelProvider(new ColumnLabelProvider());
    final List<String> registeredTemplates = new ArrayList<>(TemplateRegistry.INSTANCE.getTemplates().keySet());
    Collections.sort(registeredTemplates);
    templatesTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            templateURI = TemplateRegistry.INSTANCE.getTemplates()
                    .get(((IStructuredSelection) event.getSelection()).getFirstElement());
        }
    });
    templatesTreeViewer.setInput(registeredTemplates);

    return container;
}
 
Example 7
Source File: View2.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void createPartControl(Composite parent) {
	viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
	viewer.getTable().setLinesVisible(true);

	TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
	column.setLabelProvider(new StringLabelProvider());

	viewer.getTable().getColumn(0).setWidth(200);
	
	viewer.setContentProvider(ArrayContentProvider.getInstance());
	
	// Provide the input to the ContentProvider
	viewer.setInput(createInitialDataModel());
}
 
Example 8
Source File: FormHelper.java    From tlaplus with MIT License 5 votes vote down vote up
/**
   * Performs the inverse operation to {@link FormHelper#getSerializedInput(CheckboxTableViewer)} 
   */
  public static void setSerializedInput(TableViewer table, List<String> serializedInput)
  {
      @SuppressWarnings("unchecked")
Vector<Formula> input = ((Vector<Formula>) table.getInput());
      if (input == null)
      {
          input = new Vector<Formula>();
      }
      // handling Formulas
      if (table instanceof CheckboxTableViewer)
      {
          Iterator<String> serializedIterator = serializedInput.iterator();
          Vector<Formula> checked = new Vector<Formula>();

          CheckboxTableViewer checkTable = (CheckboxTableViewer) table;
          while (serializedIterator.hasNext())
          {
              String entry = serializedIterator.next();
              Formula formula = new Formula(entry.substring(1));
              input.add(formula);
              if ("1".equals(entry.substring(0, 1)))
              {
                  checked.add(formula);
              }
          }
          checkTable.setInput(input);
          checkTable.setCheckedElements(checked.toArray());

      } else
      // handling Assignments
      {
          List<Assignment> deserializeAssignmentList = ModelHelper.deserializeAssignmentList(serializedInput);
          table.setInput(deserializeAssignmentList);
      }

  }
 
Example 9
Source File: BuilderPropertyPage.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected TableViewer createBlackListViewer(Composite group) {
	TableViewer result = new TableViewer(group, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
	result.getTable().setLinesVisible(true);
	GridDataFactory.fillDefaults().grab(true, true).applyTo(result.getControl());
	result.setContentProvider(new ArrayContentProvider());
	result.setLabelProvider(new WorkbenchLabelProvider());
	values = blacklist.getValues(getActualProject());
	result.setInput(values);
	return result;
}
 
Example 10
Source File: AttributeEditionControl.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void createAttributeTableViewer(Composite parent) {
    viewer = new TableViewer(parent,
            SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
    viewer.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    viewer.getTable().setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, ATTRIBUTE_LIST_VIEWER_ID);
    formPage.getToolkit().adapt(viewer.getTable());
    ColumnViewerToolTipSupport.enableFor(viewer);
    viewer.setUseHashlookup(true);
    viewer.getTable().setHeaderVisible(true);
    viewer.getTable().setLinesVisible(true);
    viewer.addFilter(new SearchFilter<>(fieldToFilter));

    TableLayout layout = new TableLayout();
    layout.addColumnData(new ColumnWeightData(5, true));
    layout.addColumnData(new ColumnWeightData(4, true));
    layout.addColumnData(new ColumnWeightData(3, true));
    layout.addColumnData(new ColumnWeightData(3, true));
    viewer.getTable().setLayout(layout);

    createNameColumn(viewer);
    createTypeColumn(viewer);
    createMultipleColumn(viewer);
    createMandatoryColumn(viewer);

    viewer.setContentProvider(new ObservableListContentProvider());
    viewer.setInput(fieldsObservable);
    selectedFieldObservable = ViewerProperties.singleSelection(Field.class).observe(viewer);

    addDragAndDropSupport();
}
 
Example 11
Source File: LinkingPropertiesPage.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private <T extends CategorizedDescriptor> void fillTable(
		TableViewer table, List<T> list) {
	table.setLabelProvider(new TableLabel());
	Tables.bindColumnWidths(table, 1.0);
	list.sort((d1, d2) -> Strings.compare(
			Labels.name(d1),
			Labels.name(d2)));
	table.setInput(list);
	Tables.onDoubleClick(table, e -> {
		CategorizedDescriptor d = Viewers.getFirstSelected(table);
		App.openEditor(d);
	});
	Action copy = TableClipboard.onCopy(table);
	Actions.bind(table, copy);
}
 
Example 12
Source File: RnDialogs.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent){
	Composite ret = new Composite(parent, SWT.NONE);
	ret.setLayout(new GridLayout());
	ret.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
	Label lblSelectState = new Label(ret, SWT.NONE);
	lblSelectState.setText(Messages.RnDialogs_pleaseNewStateForMulti);
	
	cbStates = new Combo(ret, SWT.READ_ONLY);
	cbStates.setItems(RnStatus.getStatusTexts());
	cbStates.setVisibleItemCount(RnStatus.getStatusTexts().length);
	cbStates.select(rechnungen.get(0).getStatus());
	cbStates.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
	
	tableViewer = new TableViewer(ret, SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
	GridData gd_Table = new GridData();
	gd_Table.grabExcessHorizontalSpace = true;
	gd_Table.horizontalSpan = 1;
	gd_Table.minimumHeight = 150;
	gd_Table.heightHint = 150;
	tableViewer.getTable().setLayoutData(gd_Table);
	tableViewer.getTable().setHeaderVisible(true);
	tableViewer.getTable().setLinesVisible(false);
	
	tableViewer.setContentProvider(new ArrayContentProvider());
	TableViewerColumn colRnNumber = new TableViewerColumn(tableViewer, SWT.NONE);
	colRnNumber.getColumn().setWidth(200);
	colRnNumber.getColumn().setText(Messages.RnDialogs_invoiceNumber);
	colRnNumber.setLabelProvider(new ColumnLabelProvider());
	
	tableViewer.setInput(rnNumbers);
	
	return ret;
}
 
Example 13
Source File: SamplePart.java    From codeexamples-eclipse with Eclipse Public License 1.0 4 votes vote down vote up
@PostConstruct
public void createComposite(Composite parent) {
	addFonts(display);
	
	ResourceManager resManager = 
			  new LocalResourceManager(JFaceResources.getResources(), parent);
	FontDescriptor fontDescriptor = FontDescriptor.createFrom("Roboto-ThinItalic", 11, SWT.NORMAL);

	Font font = resManager.createFont(fontDescriptor);
	parent.setLayout(new GridLayout(1, false));
	
	txtInput = new Text(parent, SWT.BORDER);
	txtInput.setFont(font);
	txtInput.setMessage("Enter text to mark part as dirty");
	txtInput.addModifyListener(new ModifyListener() {
		@Override
		public void modifyText(ModifyEvent e) {
			dirty.setDirty(true);
		}
	});
	FontData fd = txtInput.getFont().getFontData()[0];
	txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	
	Text txtInput2 = new Text(parent, SWT.BORDER);
	txtInput2.setMessage("Enter text to mark part as dirty");
	txtInput2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	Button button = new Button(parent, SWT.PUSH);
	button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
	button.setFont(font);
	button.setText("Press me");
	
	
	
	Button button2 = new Button(parent, SWT.PUSH);
	button2.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
	button2.setText("Press me");

	tableViewer = new TableViewer(parent);

	tableViewer.setContentProvider(ArrayContentProvider.getInstance());;
	tableViewer.setInput(createInitialDataModel());
	tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
}
 
Example 14
Source File: UpdateTMWizardPage.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public void createContent(Composite parent) {
	TableViewer tableViewer = new TableViewer(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
	final Table table = tableViewer.getTable();
	GridData tableData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
	tableData.heightHint = 160;
	table.setLayoutData(tableData);
	table.setLinesVisible(true);
	table.setHeaderVisible(true);
	
	TableColumn columnNumber = new TableColumn(table, SWT.LEFT);
	columnNumber.setText(Messages.getString("wizard.UpdateTMWizardPage.columnNumber"));
	columnNumber.setWidth(50);
	
	TableColumn columnPath = new TableColumn(table, SWT.LEFT);
	columnPath.setText(Messages.getString("wizard.UpdateTMWizardPage.columnPath"));
	columnPath.setWidth(400);
	
	tableViewer.setLabelProvider(new TableViewerLabelProvider());
	tableViewer.setContentProvider(new ArrayContentProvider());
	tableViewer.setInput(getTableInfo());
	
	Group groupStatus = new Group(parent, SWT.None);
	groupStatus.setLayout(new GridLayout());
	groupStatus.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	groupStatus.setText(Messages.getString("dialog.UpdateTMDialog.lbl"));
	btnDraft = new Button(groupStatus, SWT.CHECK);
	btnDraft.setText(Messages.getString("dialog.UpdateTMDialog.btnDraft"));

	btnTranslated = new Button(groupStatus, SWT.CHECK);
	btnTranslated.setText(Messages.getString("dialog.UpdateTMDialog.btnTranslated"));
	btnTranslated.setSelection(true);

	btnApproved = new Button(groupStatus, SWT.CHECK);
	btnApproved.setText(Messages.getString("dialog.UpdateTMDialog.btnApproved"));
	btnApproved.setSelection(true);

	btnSignedOff = new Button(groupStatus, SWT.CHECK);
	btnSignedOff.setText(Messages.getString("dialog.UpdateTMDialog.btnSignedOff"));
	btnSignedOff.setSelection(true);
	
	btnLocked = new Button(groupStatus, SWT.CHECK);
	btnLocked.setText(Messages.getString("dialog.UpdateTMWizardPage.btnLocked"));
}
 
Example 15
Source File: IndexEditionControl.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private void createAvailableAttributesTableViewer(Composite parent) {
    Section section = formPage.getToolkit().createSection(parent, Section.EXPANDED);
    section.setLayout(GridLayoutFactory.fillDefaults().create());
    section.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    section.setText(Messages.availableAttributes);

    Composite client = formPage.getToolkit().createComposite(section);
    client.setLayout(GridLayoutFactory.fillDefaults().create());
    client.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    availableAttributesTableViewer = new TableViewer(client,
            SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    availableAttributesTableViewer.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    availableAttributesTableViewer.getTable().setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, AVAILABLE_FIELDS_VIEWER_ID);
    formPage.getToolkit().adapt(availableAttributesTableViewer.getTable());
    ColumnViewerToolTipSupport.enableFor(availableAttributesTableViewer);
    availableAttributesTableViewer.setUseHashlookup(true);
    availableAttributesTableViewer.getTable().setLinesVisible(true);
    availableAttributesTableViewer.setFilters(indexableFieldFilter, indexedFieldsFilter());

    TableLayout layout = new TableLayout();
    layout.addColumnData(new ColumnWeightData(1, true));
    availableAttributesTableViewer.getTable().setLayout(layout);

    createAttributesColumn(availableAttributesTableViewer);

    availableAttributesTableViewer.setContentProvider(new ObservableListContentProvider());
    availableAttributesTableViewer.setInput(actualsFieldsObservable);
    selectedAvailableAttributeObservable = ViewersObservables.observeMultiSelection(availableAttributesTableViewer);

    availableAttributesTableViewer.getTable().addMouseMoveListener(e -> updateCursor(e, availableAttributesTableViewer));
    availableAttributesTableViewer.addDragSupport(DND.DROP_MOVE, new Transfer[] { FieldTransfer.getInstance() },
            dragSourceAdapter(selectedAvailableAttributeObservable));
    availableAttributesTableViewer.addDropSupport(DND.DROP_MOVE,
            new Transfer[] { FieldTransfer.getInstance() },
            new DropTargetAdapter() {

                @Override
                public void drop(DropTargetEvent event) {
                    dragLeave(event);
                    indexedFieldsObservable.removeAll((Collection<?>) event.data);
                }
            });

    section.setClient(client);
}
 
Example 16
Source File: SdkEnvironmentControl.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Create the composite.
 * @param parent
 * @param style
 * @param editedSdk 
 */
public SdkEnvironmentControl(Composite parent, int style, final Sdk editedSdk) {
    super(parent, style);
    this.editedSdk = editedSdk;
    selectedVar = null;
    
    setLayoutData(new GridData(GridData.FILL_BOTH));
    setLayout(SwtUtils.removeMargins(new GridLayout(2, false)));
    
    Composite tableComposite = new Composite(this, SWT.NONE);
    tableComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    tableComposite.setLayout(new GridLayout(1, false));
    
    tableComposite.setBackground(new Color(Display.getDefault(), 255,0,0));
    
    
    tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    TableColumnLayout tableColumnLayout = new TableColumnLayout();
    tableComposite.setLayout(tableColumnLayout);
    
    tableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION);
    table = tableViewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    
    columnName = new TableViewerColumn(tableViewer, SWT.NONE);
    tblclmnName = columnName.getColumn();
    tableColumnLayout.setColumnData(tblclmnName, new ColumnPixelData(150, true, true));
    tblclmnName.setText(Messages.SdkEnvironmentControl_Variable);
    
    columnLocation = new TableViewerColumn(tableViewer, SWT.NONE);
    tblclmnLocation = columnLocation.getColumn();
    tableColumnLayout.setColumnData(tblclmnLocation, new ColumnPixelData(150, true, true));
    tblclmnLocation.setText(Messages.SdkEnvironmentControl_Value);
    tableViewer.setContentProvider(new SdkEnvContentProvider());
    tableViewer.setLabelProvider(new SdkEnvLabelProvider());
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            TableItem[] selectedItems = table.getSelection();
            boolean isEnabled = selectedItems.length > 0;
            btnEdit.setEnabled(isEnabled);
            btnDelete.setEnabled(isEnabled);
            selectedVar = isEnabled ? (String)selectedItems[0].getData() : null;
        }
    });
    
    Composite buttonsComposite = new Composite(this, SWT.NONE);
    buttonsComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    buttonsComposite.setLayout(SwtUtils.removeMargins(new GridLayout(1, false)));
    
    btnNew = SWTFactory.createPushButton(buttonsComposite, Messages.SdkEnvironmentControl_New, null);
    btnNew.addSelectionListener(new AddVarButtonHandler());
    
    btnEdit = SWTFactory.createPushButton(buttonsComposite, Messages.SdkEnvironmentControl_Edit, null);
    btnEdit.addSelectionListener(new EditValueButtonHandler());
    btnEdit.setEnabled(false);
    
    btnDelete = SWTFactory.createPushButton(buttonsComposite, Messages.SdkEnvironmentControl_Delete, null);
    btnDelete.setEnabled(false);
    btnDelete.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (selectedVar != null) {
                editedSdk.removeEnvironmentVariable(selectedVar);
                tableViewer.setInput(editedSdk);
            }
        }
    });
    tableViewer.setInput(editedSdk);
}
 
Example 17
Source File: XBookmarksDialog.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
@Override
 protected Control createDialogArea(Composite parent) {
     Composite composite = (Composite) super.createDialogArea(parent);
     GridLayoutFactory.fillDefaults().extendedMargins(Util.isWindows() ? 0 : 3, 3, 2, 2).applyTo(composite);

     Composite tableComposite = new Composite(composite, SWT.NONE);
     tableComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
     tableComposite.setLayout(new GridLayout(1, false));
     
     tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
             | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
     
     table = tableViewer.getTable();
     table.setLayoutData(new GridData(GridData.FILL_BOTH));
     tableViewer.setContentProvider(new MenuTableContentProvider());
     tableViewer.setLabelProvider(new MenuTableLabelProvider());

     { // Columns:
         GC gc= new GC(table);
         try {
         	int maxW = gc.stringExtent("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW").x; //$NON-NLS-1$
         	int gap  = gc.stringExtent("WW").x; //$NON-NLS-1$
         	int widths[] = new int[model.columns];
         	for (int i=0; i<model.columns; ++i) {
         		widths[i] = 0;
         	}
         	for (Model.Row r : model.getRows()) {
         		for (int i=0; i<model.columns; ++i) {
         			if (!r.getField(i).isEmpty()) {
         				int w     = Math.min(gc.stringExtent(r.getField(i)).x + gap, maxW);
         				widths[i] = Math.max(widths[i], w);
         			}
         		}
         	}
         	
         	for (int i=0; i<model.columns; ++i) {
         		TableColumn tc = new TableColumn(table, SWT.LEFT);
         		tc.setWidth(widths[i]);
         	}
         	table.setHeaderVisible(false);
         	table.setLinesVisible(false);
} finally {
	gc.dispose();
}
     }
     
     Listener eventListener = new Listener() {
         @Override
         public void handleEvent(Event event) {
             if (event.type == SWT.MouseDoubleClick || 
                (event.type == SWT.KeyDown && event.character == SWT.CR)) 
             {
                 doSelect();
             }
         }
         
     };
     
     addListener (SWT.KeyDown, eventListener);
     addListener (SWT.MouseDoubleClick, eventListener);
         
     tableViewer.setInput(model);
     table.select(0);

     return composite;
 }
 
Example 18
Source File: TexTableView.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This is a callback that will allow us
 * to create the viewer and initialize it.
 */
public void createPartControl(Composite parent) {
    // Create a composite to hold the children
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL
            | GridData.FILL_BOTH);
    parent.setLayoutData(gridData);

    //only one component...
    GridLayout layout = new GridLayout(1, false);
    layout.marginWidth = 4;
    parent.setLayout(layout);

    Table table = createTable(parent);

    viewer = new TableViewer(table);

    viewer.setUseHashlookup(true);
    viewer.setColumnProperties(columnNames);

    viewer.setContentProvider(new ViewContentProvider());
    viewer.setLabelProvider(new ViewLabelProvider());
    viewer.setInput(rowList);

    CellEditor[] editors = new CellEditor[TexRow.COLUMNS];

    //ICellEditorListeners
    for (int i = 0; i < TexRow.COLUMNS; i++) {
        editors[i] = new TextCellEditor(table);
        ((Text) editors[i].getControl()).setTextLimit(256);
        editors[i].getControl().addKeyListener(
                new TexCellListener(viewer, rowList, i));
    }

    // Assign the cell editors to the viewer 
    viewer.setCellEditors(editors);

    // Set the cell modifier for the viewer
    viewer.setCellModifier(new TexCellModifier(viewer, rowList));

    // Set the default sorter for the viewer 
    //viewer.setSorter(new LaTeXRowSorter(LaTeXRowSorter.COLUMN_1));
}
 
Example 19
Source File: SelectConnectorImplementationWizardPage.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.None);
    composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).extendedMargins(10, 10, 10, 0).create());
    table = new TableViewer(composite, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    table.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 200).create());
    table.setContentProvider(contentProvider);
    table.setLabelProvider(labelProvider);
    table.addSelectionChangedListener(this);
    table.addDoubleClickListener(this);

    table.setInput(new Object());

    context = new EMFDataBindingContext();

    IValidator selectionValidator = value -> {
        if (value == null) {
            return ValidationStatus.error(Messages.selectAImplWarning);
        }
        return Status.OK_STATUS;
    };

    UpdateValueStrategy selectionStrategy = new UpdateValueStrategy();
    selectionStrategy.setBeforeSetValidator(selectionValidator);

    context.bindValue(ViewersObservables.observeSingleSelection(table),
            PojoProperties.value(SelectConnectorImplementationWizardPage.class, "selectedImplementation").observe(this),
            selectionStrategy, null);

    removeButton = new Button(composite, SWT.PUSH);
    removeButton.setText(Messages.remove);
    removeButton.setLayoutData(GridDataFactory.swtDefaults().hint(85, SWT.DEFAULT).create());
    removeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (selectedImplementation != null) {
                String fileName = URI.decode(selectedImplementation.eResource().getURI().lastSegment());
                IRepositoryFileStore file = implStore.getChild(fileName, true);
                file.delete();
                refresh();
            }
        }
    });
    removeButton.setEnabled(false);

    pageSupport = WizardPageSupport.create(this, context);
    setControl(composite);
}
 
Example 20
Source File: ExcelFileSelectionWizardPage.java    From birt with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * display the content of the list in the table viewer
 * 
 * @param list
 *            list that contains the dispay content
 * @param tViewer
 *            the table viewer
 */
private void setDisplayContent( java.util.List<String[]> list,
		TableViewer tViewer )
{
	tViewer.getTable( ).removeAll( );
	tViewer.setInput( list );
	tViewer.getTable( ).select( tViewer.getTable( ).getTopIndex( ) );
}