List of usage examples for org.eclipse.jface.viewers TableViewer TableViewer
public TableViewer(Composite parent, int style)
From source file:com.bdaum.zoom.ui.internal.preferences.PerspectivesPreferencePage.java
License:Open Source License
/** * Create a table of 3 buttons to enable the user to manage customized * perspectives./* ww w . j a v a 2s .c o m*/ * * @param parent * the parent for the button parent * @return Composite that the buttons are created in. */ protected Composite createCustomizePerspective(Composite parent) { Composite perspectivesComponent = new Composite(parent, SWT.NONE); perspectivesComponent.setLayoutData(new GridData(GridData.FILL_BOTH)); perspectivesComponent.setLayout(new GridLayout(2, false)); Label description = new Label(perspectivesComponent, SWT.WRAP); description.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1)); description.setText(Messages.getString("PerspectivesPreferencePage.perspectives_organize")); //$NON-NLS-1$ new Label(perspectivesComponent, SWT.NONE) .setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1)); CGroup perspGroup = UiUtilities.createGroup(perspectivesComponent, 2, Messages.getString("PerspectivesPreferencePage.available_perspectives")); //$NON-NLS-1$ viewer = new TableViewer(perspGroup, SWT.V_SCROLL | SWT.FULL_SELECTION); viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { updateButtons(); } }); viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); viewer.setContentProvider(ArrayContentProvider.getInstance()); viewer.setComparator(ZViewerComparator.INSTANCE); TableViewerColumn col1 = new TableViewerColumn(viewer, SWT.NONE); col1.getColumn().setWidth(180); col1.setLabelProvider(new ZColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof IPerspectiveDescriptor) return ((IPerspectiveDescriptor) element).getLabel(); return element.toString(); } }); TableViewerColumn col2 = new TableViewerColumn(viewer, SWT.NONE); col2.getColumn().setWidth(120); col2.setLabelProvider(new ZColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof IPerspectiveDescriptor) return isPredefined((IPerspectiveDescriptor) element) ? Messages.getString("PerspectivesPreferencePage.predefined") //$NON-NLS-1$ : Messages.getString("PerspectivesPreferencePage.user_defined"); //$NON-NLS-1$ return element.toString(); } }); IPerspectiveDescriptor[] persps = perspectiveRegistry.getPerspectives(); perspectives = new ArrayList<IPerspectiveDescriptor>(persps.length); for (int i = 0; i < persps.length; i++) perspectives.add(i, persps[i]); viewer.setInput(perspectives); createVerticalButtonBar(perspGroup); return perspectivesComponent; }
From source file:com.bdaum.zoom.ui.internal.views.BookmarkView.java
License:Open Source License
@SuppressWarnings("unused") @Override/*w w w .j a va2s . c o m*/ public void createPartControl(final Composite parent) { Composite area = new Composite(parent, SWT.NONE); area.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); area.setLayout(new GridLayout(1, false)); viewer = new TableViewer(area, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), HelpContextIds.BOOKMARK_VIEW); final TableViewerColumn col1 = createColumn(viewer, Messages.getString("BookmarkView.image"), //$NON-NLS-1$ COLUMNWIDTHS[0]); final ColumnLabelProvider assetLabelProvider = new ColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof Bookmark) { Bookmark bookmark = (Bookmark) element; String label = bookmark.getLabel(); String peer = bookmark.getPeer(); String catFile = bookmark.getCatFile(); return catFile != null && !catFile.isEmpty() ? (peer != null) ? NLS.bind("{0} ({1}, {2})", //$NON-NLS-1$ new Object[] { label, peer, new File(catFile).getName() }) : NLS.bind("{0} ({1})", label, //$NON-NLS-1$ new File(catFile).getName()) : label; } return super.getText(element); } @Override public Image getImage(Object element) { if (element instanceof Bookmark) { byte[] jpegImage = ((Bookmark) element).getJpegImage(); if (jpegImage != null && jpegImage.length > 0) { Image image = ImageUtilities.loadThumbnail(getSite().getShell().getDisplay(), jpegImage, Ui.getUi().getDisplayCMS(), SWT.IMAGE_JPEG, false); Image smallImage = ImageUtilities.scaleSWT(image, 24, 24, true, 0, true, parent.getBackground()); images.add(smallImage); return smallImage; } } return null; } }; col1.setLabelProvider(assetLabelProvider); col1.setEditingSupport(new EditingSupport(viewer) { @Override protected void setValue(Object element, Object value) { if (element instanceof Bookmark && value instanceof String) { ((Bookmark) element).setLabel((String) value); Core.getCore().getDbManager().safeTransaction(null, element); viewer.update(element, null); } } @Override protected Object getValue(Object element) { if (element instanceof Bookmark) return ((Bookmark) element).getLabel(); return null; } @Override protected CellEditor getCellEditor(Object element) { return new TextCellEditor(viewer.getTable()); } @Override protected boolean canEdit(Object element) { return element instanceof Bookmark; } }); final TableViewerColumn col2 = createColumn(viewer, Messages.getString("BookmarkView.collection"), //$NON-NLS-1$ COLUMNWIDTHS[1]); final ICore core = Core.getCore(); final ColumnLabelProvider collectionLabelProvider = new ColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof Bookmark) { SmartCollectionImpl sm = core.getDbManager().obtainById(SmartCollectionImpl.class, ((Bookmark) element).getCollectionId()); return sm == null ? "" : sm.getName(); //$NON-NLS-1$ } return super.getText(element); } }; col2.setLabelProvider(collectionLabelProvider); final TableViewerColumn col3 = createColumn(viewer, Messages.getString("BookmarkView.created"), //$NON-NLS-1$ COLUMNWIDTHS[2]); final ColumnLabelProvider dateLabelProvider = new ColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof Bookmark) { Date createdAt = ((Bookmark) element).getCreatedAt(); return createdAt == null ? "" : DATEFORMAT.format(createdAt); //$NON-NLS-1$ } return super.getText(element); } }; col3.setLabelProvider(dateLabelProvider); Table table = viewer.getTable(); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); table.setHeaderVisible(true); table.setLinesVisible(true); viewer.setContentProvider(new IStructuredContentProvider() { public void inputChanged(Viewer aViewer, Object oldInput, Object newInput) { // do nothing } public void dispose() { disposeImages(); } public Object[] getElements(Object inputElement) { final IDbManager dbManager = Core.getCore().getDbManager(); List<BookmarkImpl> bookmarks = dbManager.obtainObjects(BookmarkImpl.class); List<BookmarkImpl> existingBookmarks = new ArrayList<BookmarkImpl>(50); final List<Object> tobeDeleted = new ArrayList<Object>(); for (BookmarkImpl bookmark : bookmarks) { if (bookmark.getCatFile() != null && !bookmark.getCatFile().isEmpty()) existingBookmarks.add(bookmark); else if (!dbManager.exists(AssetImpl.class, bookmark.getAssetId())) tobeDeleted.add(bookmark); else existingBookmarks.add(bookmark); } if (!tobeDeleted.isEmpty()) dbManager.safeTransaction(tobeDeleted, null); return existingBookmarks.toArray(); } }); viewer.setComparator(new ViewerComparator() { @Override public int compare(Viewer aViewer, Object e1, Object e2) { if (sortColumn == col3.getColumn()) { Date d1 = ((Bookmark) e1).getCreatedAt(); Date d2 = ((Bookmark) e2).getCreatedAt(); return d1 == null || d2 == null ? 0 : (sortDirection == SWT.DOWN) ? d1.compareTo(d2) : d2.compareTo(d1); } ColumnLabelProvider labelProvider; if (sortColumn == col1.getColumn()) labelProvider = assetLabelProvider; else labelProvider = collectionLabelProvider; String s1 = labelProvider.getText(e1); String s2 = labelProvider.getText(e2); return (sortDirection == SWT.DOWN) ? s1.compareToIgnoreCase(s2) : s2.compareToIgnoreCase(s1); } }); addPartListener(); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { updateActions(); } }); new ColumnLayoutManager(viewer, COLUMNWIDTHS, null); switchSort(table, col1.getColumn()); new AssetDragSourceListener(this, DND.DROP_COPY | DND.DROP_MOVE); new BookmarkDropTargetListener(DND.DROP_MOVE | DND.DROP_COPY); makeActions(); hookContextMenu(); hookDoubleClickAction(); contributeToActionBars(); installHoveringController(); core.addCatalogListener(this); catalogOpened(false); }
From source file:com.bdaum.zoom.ui.internal.views.TableView.java
License:Open Source License
private void createGallery(Composite parent, boolean recreate) { gallery = new TableViewer(parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); PlatformUI.getWorkbench().getHelpSystem().setHelp(gallery.getControl(), HelpContextIds.TABLE_VIEW); themeChanged();//from w w w. java2s . c om gallery.setContentProvider(new ILazyContentProvider() { public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // do nothing } public void dispose() { // do nothing } public void updateElement(int index) { IAssetProvider assetProvider = getAssetProvider(); if (assetProvider != null) { Asset asset = assetProvider.getAsset(index); if (asset != null) { synchronized (gallery) { gallery.replace(asset, index); } } } } }); final Table table = gallery.getTable(); if (!recreate) setAppStarting(table); table.setLinesVisible(true); table.setHeaderVisible(true); // Construct columns List<String> props = new ArrayList<String>(); imageColumn = new TableViewerColumn(gallery, SWT.NONE); TableColumn icolumn = imageColumn.getColumn(); icolumn.setWidth(thumbsize); icolumn.setResizable(false); icolumn.setText(Messages.getString("TableView.configure")); //$NON-NLS-1$ imageColumn.setLabelProvider(new ThumbnailLabelProvider()); icolumn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ConfigureColumnsDialog dialog = new ConfigureColumnsDialog(getSite().getShell()); dialog.create(); dialog.getShell().setLocation(gallery.getControl().toDisplay(e.x, e.y)); dialog.open(); } }); props.add("$"); //$NON-NLS-1$ QueryField scoreField = QueryField.SCORE; scoreColumn = createColumn(table, scoreField, Messages.getString("TableView.score"), 50, //$NON-NLS-1$ new MetaDataLabelProvider(scoreField)); props.add(scoreField.getKey()); StringTokenizer st = new StringTokenizer( UiActivator.getDefault().getPreferenceStore().getString(PreferenceConstants.TABLECOLUMNS), "\n"); //$NON-NLS-1$ displayedFields.clear(); while (st.hasMoreTokens()) { String id = st.nextToken(); QueryField qfield = QueryField.findQueryField(id); if (qfield != null) { displayedFields.add(qfield); createColumn(table, qfield, qfield.getLabel(), 120, new MetaDataLabelProvider(qfield)); props.add(id); } } gallery.setColumnProperties(props.toArray(new String[props.size()])); gallery.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (refreshing <= 0) { stopAudio(); selection = doGetAssetSelection(); fireSelection(); } } }); ZColumnViewerToolTipSupport.enableFor(gallery); addKeyListener(); addGestureListener(gallery.getTable()); addExplanationListener(false); addDragDropSupport(); hookContextMenu(); hookDoubleClickAction(); }
From source file:com.blackducksoftware.integration.eclipseplugin.views.ui.VulnerabilityView.java
License:Apache License
@Override public void createPartControl(Composite parent) { GridLayout parentLayout = new GridLayout(1, false); parentLayout.marginWidth = 0;/*from ww w .j a va2s .co m*/ parentLayout.marginHeight = 0; parent.setLayout(parentLayout); workspaceInformationService = new WorkspaceInformationService( new ProjectInformationService(new DependencyInformationService(), new FilePathGavExtractor())); display = PlatformUI.getWorkbench().getDisplay(); Activator.getPlugin().getProjectInformation().setComponentView(this); lastSelectedProjectName = workspaceInformationService.getSelectedProject(); setUpHeaderComposite(parent); // ComponentFilter componentFilter = new ComponentFilter(filterBox); dependencyTableViewer = new TableViewer(parent, (SWT.VIRTUAL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL)); dependencyTableViewer.setUseHashlookup(true); dependencyTableViewer.getTable().setHeaderVisible(true); dependencyTableViewer.getTable().setLinesVisible(true); dependencyTableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); dependencyTableViewer.addDoubleClickListener(new TableDoubleClickListener(this)); contentProvider = new DependencyTableViewContentProvider(this, dependencyTableViewer); // contentProvider.addFilter(componentFilter); dependencyTableViewer.setContentProvider(contentProvider); projectSelectionListener = new ProjectSelectionListener(this); getSite().getPage().addSelectionListener(projectSelectionListener); this.createColumns(); this.resetInput(); tableStatus = new CLabel(parent, SWT.LEFT); tableStatus.setText(InspectionStatus.INITIALIZING); tableStatus.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); preferenceChangeDisplayUpdateListener = new PreferenceChangeDisplayUpdateListener(this); projectDeletedListener = new ProjectDeletedListener(this); Activator.getPlugin().getPreferenceStore().addPropertyChangeListener(preferenceChangeDisplayUpdateListener); ResourcesPlugin.getWorkspace().addResourceChangeListener(projectDeletedListener, IResourceChangeEvent.PRE_DELETE); }
From source file:com.bmw.spdxeditor.editors.spdx.SPDXEditor.java
License:Apache License
/** * Create the license text editor component * //ww w .j av a 2s . c om * @param parent * @return * @throws InvalidSPDXAnalysisException */ private Group createLicenseTextEditor(Composite parent) throws InvalidSPDXAnalysisException { Group licenseTextEditorGroup = new Group(parent, SWT.SHADOW_ETCHED_IN); licenseTextEditorGroup.setText("Licenses referenced in SPDX file"); GridLayout licenseTextEditorGroupLayout = new GridLayout(); licenseTextEditorGroupLayout.numColumns = 2; licenseTextEditorGroup.setLayout(licenseTextEditorGroupLayout); // Add table viewer final TableViewer tableViewer = new TableViewer(licenseTextEditorGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); // The list of available extracted license texts final Table table = tableViewer.getTable(); table.setToolTipText("Right click to add/remove licenses."); // Build a drop down menu to add/remove licenses Menu licenseTableMenu = new Menu(parent.getShell(), SWT.POP_UP); MenuItem addNewLicenseText = new MenuItem(licenseTableMenu, SWT.PUSH); addNewLicenseText.setText("Add license text"); addNewLicenseText.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // Retrieve the corresponding Services IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class); ICommandService commandService = (ICommandService) getSite().getService(ICommandService.class); // Retrieve the command Command generateCmd = commandService.getCommand("SPDXEditor.addNewLicenseText"); // Create an ExecutionEvent ExecutionEvent executionEvent = handlerService.createExecutionEvent(generateCmd, new Event()); // Launch the command try { generateCmd.executeWithChecks(executionEvent); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) { MessageDialog.openError(getSite().getShell(), "Execution failed", e1.getMessage()); } } }); // Listen for changes on model this.getInput().addChangeListener(new IResourceChangeListener() { @Override public void resourceChanged(IResourceChangeEvent event) { try { SPDXNonStandardLicense[] nonStandardLicenses = getInput().getAssociatedSPDXFile() .getExtractedLicenseInfos(); tableViewer.setInput(nonStandardLicenses); tableViewer.refresh(); loadLicenseDataFromSPDXFile(); setLicenseComboBoxValue(concludedLicenseChoice, getInput().getAssociatedSPDXFile().getSpdxPackage().getConcludedLicenses()); // populateLicenseSelectorWithAvailableLicenses(declaredLicenseChoice); setLicenseComboBoxValue(declaredLicenseChoice, getInput().getAssociatedSPDXFile().getSpdxPackage().getDeclaredLicense()); setDirtyFlag(true); } catch (InvalidSPDXAnalysisException e) { e.printStackTrace(); } } }); final MenuItem deleteSelectedLicenseTexts = new MenuItem(licenseTableMenu, SWT.PUSH); deleteSelectedLicenseTexts.setText("Delete licenses"); deleteSelectedLicenseTexts.setEnabled(false); tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { // Never enable, not yet implemented // deleteSelectedLicenseTexts.setEnabled(table.getSelectionCount() // != 0); } }); table.setMenu(licenseTableMenu); // Make headers and borders visible table.setHeaderVisible(true); table.setLinesVisible(true); tableViewer.setContentProvider(ArrayContentProvider.getInstance()); // Create TableViewerColumn for each column TableViewerColumn viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE); viewerNameColumn.getColumn().setText("License ID"); viewerNameColumn.getColumn().setWidth(100); // Set LabelProvider for each column viewerNameColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { SPDXNonStandardLicense licenseInCell = (SPDXNonStandardLicense) cell.getElement(); cell.setText(licenseInCell.getId()); } }); viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE); viewerNameColumn.getColumn().setText("License text"); viewerNameColumn.getColumn().setWidth(100); viewerNameColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { SPDXNonStandardLicense iteratorLicense = (SPDXNonStandardLicense) cell.getElement(); cell.setText(iteratorLicense.getText()); } }); /* * All ExtractedLicensingInfo is contained in the SPDX file assigned to * the input. */ tableViewer.setInput(getInput().getAssociatedSPDXFile().getExtractedLicenseInfos()); GridData spdxDetailsPanelGridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); spdxDetailsPanelGridData.horizontalSpan = 1; spdxDetailsPanelGridData.heightHint = 150; licenseTextEditorGroup.setLayoutData(spdxDetailsPanelGridData); GridData gridData = new GridData(); gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalAlignment = GridData.FILL; gridData.horizontalSpan = 1; gridData.heightHint = 100; gridData.minimumWidth = 70; tableViewer.getControl().setLayoutData(gridData); /* * Text editor field for editing license texts. */ final Text licenseEditorText = new Text(licenseTextEditorGroup, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); licenseEditorText.setText(""); licenseEditorText.setEditable(true); GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false); gd.minimumHeight = 70; gd.minimumWidth = 200; gd.heightHint = 100; gd.horizontalSpan = 1; licenseEditorText.setLayoutData(gd); licenseEditorText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { try { SPDXNonStandardLicense[] nonStandardLicenses; nonStandardLicenses = getInput().getAssociatedSPDXFile().getExtractedLicenseInfos(); nonStandardLicenses[table.getSelectionIndex()].setText(licenseEditorText.getText()); setDirtyFlag(true); } catch (InvalidSPDXAnalysisException e1) { MessageDialog.openError(getSite().getShell(), "SPDX Analysis error", e1.getMessage()); } } }); /* * Listener for updating text editor selection based on selected table * entry. */ table.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { SPDXNonStandardLicense[] nonStandardLicenses; try { nonStandardLicenses = getInput().getAssociatedSPDXFile().getExtractedLicenseInfos(); licenseEditorText.setText(nonStandardLicenses[table.getSelectionIndex()].getText()); } catch (InvalidSPDXAnalysisException e1) { MessageDialog.openError(getSite().getShell(), "SPDX Analysis invalid", e1.getMessage()); } } }); // Style group panel GridData licenseTextEditorGroupGridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); licenseTextEditorGroupGridData.horizontalSpan = 2; licenseTextEditorGroup.setLayoutData(licenseTextEditorGroupGridData); return licenseTextEditorGroup; }
From source file:com.bmw.spdxeditor.editors.spdx.SPDXEditor.java
License:Apache License
/** * Create the linked files group panel/* w ww . j a v a 2 s .co m*/ * * @param parent * @return * @throws InvalidSPDXAnalysisException */ private Composite createLinkedFilesDetailsPanel(Composite parent) throws InvalidSPDXAnalysisException { Group linkedFilesDetailsGroup = new Group(parent, SWT.SHADOW_ETCHED_IN); linkedFilesDetailsGroup.setText("Referenced files"); GridLayout linkedFilesDetailsGroupLayout = new GridLayout(); linkedFilesDetailsGroup.setLayout(linkedFilesDetailsGroupLayout); // Add table viewer final TableViewer tableViewer = new TableViewer(linkedFilesDetailsGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); GridData gridData = new GridData(); gridData.verticalAlignment = GridData.FILL; gridData.horizontalAlignment = GridData.FILL; gridData.heightHint = 80; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; tableViewer.getControl().setLayoutData(gridData); // SWT Table final Table table = tableViewer.getTable(); table.setToolTipText("Right-click to add or remove files"); // Make header and columns visible table.setHeaderVisible(true); table.setLinesVisible(true); tableViewer.setContentProvider(ArrayContentProvider.getInstance()); // Add context menu to TableViewer Menu linkesFileTableMenu = new Menu(parent.getShell(), SWT.POP_UP); MenuItem addNewLicenseText = new MenuItem(linkesFileTableMenu, SWT.PUSH); addNewLicenseText.setText("Add source code archive"); addNewLicenseText.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // Retrieve the corresponding Services IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class); ICommandService commandService = (ICommandService) getSite().getService(ICommandService.class); // Retrieve the command Command generateCmd = commandService.getCommand("SPDXEditor.addLinkedSourceCodeFile"); // Create an ExecutionEvent ExecutionEvent executionEvent = handlerService.createExecutionEvent(generateCmd, new Event()); // Launch the command try { generateCmd.executeWithChecks(executionEvent); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) { MessageDialog.openError(getSite().getShell(), "Error", e1.getMessage()); } } }); final MenuItem deleteSelectedLicenseTexts = new MenuItem(linkesFileTableMenu, SWT.PUSH); deleteSelectedLicenseTexts.setText("Delete selected source code archive"); deleteSelectedLicenseTexts.setEnabled(false); deleteSelectedLicenseTexts.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // Retrieve the corresponding Services IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class); ICommandService commandService = (ICommandService) getSite().getService(ICommandService.class); // Retrieve the command Command generateCmd = commandService.getCommand("SPDXEditor.removedLinkedSourceCodeFile"); // Create an ExecutionEvent ExecutionEvent executionEvent = handlerService.createExecutionEvent(generateCmd, new Event()); // Launch the command try { generateCmd.executeWithChecks(executionEvent); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) { MessageDialog.openError(getSite().getShell(), "Error", e1.getMessage()); } } }); table.setMenu(linkesFileTableMenu); tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { deleteSelectedLicenseTexts.setEnabled(table.getSelectionCount() != 0); } }); // Create TableViewer for each column TableViewerColumn viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE); viewerNameColumn.getColumn().setText("File name"); viewerNameColumn.getColumn().setWidth(160); viewerNameColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { SPDXFile currentFile = (SPDXFile) cell.getElement(); cell.setText(currentFile.getName()); } }); viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE); viewerNameColumn.getColumn().setText("Type"); viewerNameColumn.getColumn().setWidth(120); viewerNameColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { SPDXFile currentFile = (SPDXFile) cell.getElement(); cell.setText(currentFile.getType()); } }); // License choice for file viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE); viewerNameColumn.getColumn().setText("Concluded License"); viewerNameColumn.getColumn().setWidth(120); // // LabelProvider fr jede Spalte setzen viewerNameColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { SPDXFile currentFile = (SPDXFile) cell.getElement(); SPDXLicenseInfo spdxConcludedLicenseInfo = currentFile.getConcludedLicenses(); cell.setText(getLicenseIdentifierTextForLicenseInfo(spdxConcludedLicenseInfo)); } }); viewerNameColumn = new TableViewerColumn(tableViewer, SWT.NONE); viewerNameColumn.getColumn().setText("SHA1 hash"); viewerNameColumn.getColumn().setWidth(120); // LabelProvider fr jede Spalte setzen viewerNameColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { SPDXFile currentFile = (SPDXFile) cell.getElement(); cell.setText(currentFile.getSha1()); } }); SPDXFile[] referencedFiles = getInput().getAssociatedSPDXFile().getSpdxPackage().getFiles(); tableViewer.setInput(referencedFiles); getSite().setSelectionProvider(tableViewer); this.getInput().addChangeListener(new IResourceChangeListener() { @Override public void resourceChanged(IResourceChangeEvent event) { SPDXFile[] referencedFiles; try { referencedFiles = getInput().getAssociatedSPDXFile().getSpdxPackage().getFiles(); tableViewer.setInput(referencedFiles); tableViewer.refresh(); setDirtyFlag(true); } catch (InvalidSPDXAnalysisException e) { MessageDialog.openError(getSite().getShell(), "SPDX Analysis invalid", e.getMessage()); } } }); GridData spdxDetailsPanelGridData = new GridData(SWT.FILL, SWT.BEGINNING, true, true); spdxDetailsPanelGridData.horizontalSpan = 1; spdxDetailsPanelGridData.grabExcessVerticalSpace = true; spdxDetailsPanelGridData.grabExcessHorizontalSpace = true; spdxDetailsPanelGridData.minimumHeight = 90; linkedFilesDetailsGroup.setLayoutData(spdxDetailsPanelGridData); return linkedFilesDetailsGroup; }
From source file:com.buglabs.dragonfly.ui.wizards.bugProject.BUGModuleServiceBindingPage.java
License:Open Source License
public void createControl(Composite parent) { try {/*from w w w .ja va 2s .com*/ Composite mainComposite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(1, false); mainComposite.setLayout(layout); mainComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); Composite msComp = new Composite(mainComposite, SWT.None); msComp.setLayout(new GridLayout(2, false)); msComp.setLayoutData(new GridData(GridData.FILL_BOTH)); final TableViewer moduleViewer = new TableViewer(msComp, SWT.BORDER | SWT.V_SCROLL); moduleViewer.getTable().setLayoutData(getModuleViewerLayoutData()); moduleViewer.setContentProvider(new BUGStaticServiceContentProvider()); moduleViewer.setLabelProvider(new BUGStaticServiceLabelProvider()); //Load the bug module model from static data provided in the plugin. moduleModel = BUGModule.load(getModuleModel()); moduleViewer.setInput(moduleModel); Composite rComp = new Composite(msComp, SWT.None); rComp.setLayout(UIUtils.StripGridLayoutMargins(new GridLayout())); rComp.setLayoutData(new GridData(GridData.FILL_BOTH)); serviceViewer = new CheckboxTableViewer(createServiceTable(rComp)); serviceViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); serviceViewer.setContentProvider(new BUGServiceContentProvider()); serviceViewer.setLabelProvider(new BUGServiceLabelProvider()); serviceViewer.setInput(null); serviceViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { BUGModuleService bms = (BUGModuleService) ((IStructuredSelection) serviceViewer.getSelection()) .getFirstElement(); if (bms != null) { bms.setSelected(event.getChecked()); } updateModel(); } }); final Text serviceDescText = new Text(rComp, SWT.MULTI | SWT.WRAP); serviceDescText.setLayoutData(getDescriptionLabelLayoutData()); serviceDescText.setBackground( PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW)); moduleViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { BUGModule bm = (BUGModule) ((IStructuredSelection) moduleViewer.getSelection()) .getFirstElement(); serviceViewer.setInput(bm); serviceDescText.setText(bm.getDescription()); for (BUGModuleService bms : bm.getServices()) { if (bms.isSelected()) serviceViewer.setChecked(bms, true); } } }); serviceViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { BUGModuleService bms = (BUGModuleService) ((IStructuredSelection) serviceViewer.getSelection()) .getFirstElement(); if (bms != null) { if (bms.getDescription() == null) { serviceDescText.setText(""); } else { serviceDescText.setText(bms.getDescription()); } } else { serviceDescText.setText(""); } } }); setControl(mainComposite); } catch (IOException e) { UIUtils.handleVisualError("Failed to load module data.", e); } }
From source file:com.buglabs.dragonfly.ui.wizards.bugProject.OSGiServiceBindingPage.java
License:Open Source License
/** * Creates TableViewer that has all BUGs currently available in MyBUGs view * /* w w w . j a va 2s . c om*/ * @param composite */ private void createTargetArea(final Composite parent) { Group composite = new Group(parent, SWT.NONE); composite.setText(TARGET_BUG_TITLE); composite.setLayout(new GridLayout(2, false)); GridData gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.grabExcessHorizontalSpace = true; composite.setLayoutData(gridData); GridData gdLabel = new GridData(GridData.FILL_HORIZONTAL); gdLabel.horizontalSpan = 2; Label label = new Label(composite, SWT.NONE); label.setText(TARGET_BUG_INSTRUCTIONS); label.setLayoutData(gdLabel); GridData fillHorizontal = new GridData(GridData.FILL_HORIZONTAL); GridData gdViewer = GridDataFactory.createFrom(fillHorizontal).create(); gdViewer.heightHint = BUGS_VIEWER_HEIGHT_HINT; bugsViewer = new TableViewer(composite, SWT.BORDER | SWT.V_SCROLL); bugsViewer.getTable().setLayoutData(gdViewer); // set up change listener bugsViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { // not sure why this would be the case, but return if nothing there if (((BaseTreeNode) bugsViewer.getInput()).getChildren().size() == 0) return; // don't do anything if it's the same as the previous selection ISelection selection = event.getSelection(); if (currentBugSelection != null && currentBugSelection.equals(selection)) return; if (!reloadListDialog(parent.getShell())) { if (currentBugSelection != null) event.getSelectionProvider().setSelection(currentBugSelection); return; } // Make sure we can connect to the given BUG final BugConnection connection = (BugConnection) ((StructuredSelection) event.getSelection()) .getFirstElement(); if (connection == null) return; // set the saved currentBugSelection to the selection currentBugSelection = selection; // prepare to launch refresh services job refreshServiceDefintions.setEnabled(true); // clear selections clearSelections(); launchRefreshServicesJob(connection); } }); bugsViewer.setContentProvider(new MyBugsViewContentProvider() { public Object[] getChildren(Object parentElement) { if (parentElement instanceof BaseTreeNode) { return ((BaseTreeNode) parentElement).getChildren().toArray(); } return new Object[0]; } }); bugsViewer.setLabelProvider(new LabelProvider() { public String getText(Object element) { if (element instanceof BugConnection) { return ((BugConnection) element).getName(); } else { return super.getText(element); } } public Image getImage(Object element) { if (element instanceof BugConnection) { return Activator.getDefault().getImageRegistry().get(Activator.IMAGE_COLOR_UPLOAD); } return super.getImage(element); } }); BaseTreeNode root = (BaseTreeNode) BugConnectionManager.getInstance().getBugConnectionsRoot(); bugsViewer.setInput(root); btnStartVBUG = new Button(composite, SWT.PUSH); btnStartVBUG.setText(START_VIRTUAL_BUG_LABEL); btnStartVBUG.setToolTipText(START_VIRTUAL_BUG_TOOLTIP); GridData gdButton = new GridData(); gdButton.verticalAlignment = SWT.TOP; btnStartVBUG.setLayoutData(gdButton); btnStartVBUG.addSelectionListener(((SelectionListener) new StartVBUGSelectionListener())); setPageMessage(root.getChildren().size()); }
From source file:com.byterefinery.rmbench.database.mysql.EnumAndSetDialog.java
License:Open Source License
private void createListViewer(Composite parent) { typesViewer = new TableViewer(parent, SWT.BORDER); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.verticalSpan = 4;/*from w w w . j a v a2 s .c o m*/ typesViewer.getControl().setLayoutData(gd); typesViewer.setLabelProvider(new TypeLabelProvider()); typesViewer.setContentProvider(new TypesContentProvider()); typesViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection sel = (IStructuredSelection) event.getSelection(); if (sel.isEmpty()) { deleteButton.setEnabled(false); return; } inputText.setText((String) sel.getFirstElement()); deleteButton.setEnabled(true); } }); }
From source file:com.byterefinery.rmbench.dialogs.ConnectionDialog.java
License:Open Source License
protected Control createDialogArea(Composite parent) { //parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); Composite comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); viewer = new TableViewer(comp, SWT.BORDER); viewer.setContentProvider(new DBModelContentProvider()); viewer.setLabelProvider(new DBModelLabelProvider()); Table table = viewer.getTable();//from w ww . jav a2 s . c o m table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); table.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (viewer.getSelection().isEmpty()) { editButton.setImage(RMBenchPlugin.getImage(ImageConstants.EDIT_disabled)); editButton.setEnabled(false); removeButton.setImage(ImageConstants.DELETE_DISABLED_IMG); removeButton.setEnabled(false); return; } editButton.setImage(RMBenchPlugin.getImage(ImageConstants.EDIT)); editButton.setEnabled(true); removeButton.setImage(ImageConstants.DELETE_IMG); removeButton.setEnabled(true); } }); TableLayout layout = new TableLayout(); table.setLayout(layout); table.setHeaderVisible(true); TableColumn tc = new TableColumn(table, SWT.NONE); tc.setText(Messages.ConnectionDialog_connection_name); layout.addColumnData(new ColumnWeightData(50)); tc = new TableColumn(table, SWT.NONE); tc.setText(Messages.ConnectionDialog_database_name); layout.addColumnData(new ColumnWeightData(50)); Composite tableButtonComposite = createTableButtonBar(comp); GridData gridData = new GridData(SWT.NONE, SWT.FILL, false, true); gridData.verticalAlignment = SWT.CENTER; tableButtonComposite.setLayoutData(gridData); viewer.setInput(RMBenchPlugin.getDefault().getDBModels()); listener.register(); return comp; }