List of usage examples for org.eclipse.jface.viewers TableViewer setContentProvider
@Override public void setContentProvider(IContentProvider provider)
AbstractTableViewer
. From source file:com.bluexml.side.Class.modeler.diagram.dialogs.ClazzEditDialog.java
License:Open Source License
/** * // w ww . jav a 2 s . c om * @param composite */ private void createTableViewer(Composite panelTable) { int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION; table = new Table(panelTable, style); TableColumn aspectColumn = new TableColumn(table, SWT.LEFT); aspectColumn.setText("Aspects"); aspectColumn.setWidth(350); table.setHeaderVisible(true); table.setLinesVisible(true); GridData gridData = new GridData(GridData.FILL_BOTH); gridData.grabExcessVerticalSpace = true; gridData.horizontalSpan = 2; table.setLayoutData(gridData); TableViewer tableViewer = new TableViewer(table); tableViewer.setUseHashlookup(true); tableViewer.setColumnProperties(new String[] { "Aspects" }); tableViewer.setContentProvider(new AspectContentProvider()); tableViewer.setLabelProvider(new AspectLabelProvider()); tableViewer.setInput(classe.getAspects()); }
From source file:com.bmw.spdxeditor.editors.spdx.SPDXEditor.java
License:Apache License
/** * Create the license text editor component * //from w w w. j a v a 2 s . c o m * @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/*www . j av a 2 s . c o 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 ww w. j a v a 2 s. c o m*/ 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.contrastsecurity.ide.eclipse.ui.internal.preferences.ContrastPreferencesPage.java
License:Open Source License
private TableViewer createTableViewer(Composite composite) { TableViewer tableViewer = new TableViewer(composite, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); tableViewer.getTable().setLayoutData(gd); tableViewer.getTable().setHeaderVisible(true); tableViewer.getTable().setLinesVisible(true); tableViewer.setContentProvider(ArrayContentProvider.getInstance()); TableLayout layout = new TableLayout(); tableViewer.getTable().setLayout(layout); TableColumn orgNameColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); orgNameColumn.setText("Organization"); orgNameColumn.setWidth(180);//ww w .j a v a 2 s . c o m String[] list = ContrastCoreActivator.getOrganizationList(); tableViewer.setInput(list); if (list.length > 0) { String orgName = ContrastCoreActivator.getDefaultOrganization(); if (orgName != null && !orgName.isEmpty()) { tableViewer.getTable().setSelection(ArrayUtils.indexOf(list, orgName)); } else { tableViewer.getTable().setSelection(0); } } return tableViewer; }
From source file:com.contrastsecurity.ide.eclipse.ui.internal.views.TagDialog.java
License:Open Source License
private TableViewer createTableViewer(Composite composite) { TableViewer tableViewer = new TableViewer(composite, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); tableViewer.getTable().setLayoutData(gd); tableViewer.setLabelProvider(new TagLabelProvider()); tableViewer.getTable().setHeaderVisible(true); tableViewer.getTable().setLinesVisible(true); tableViewer.setContentProvider(ArrayContentProvider.getInstance()); TableLayout layout = new TableLayout(); tableViewer.getTable().setLayout(layout); TableColumn tagColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); tagColumn.setText("Tag"); tagColumn.setWidth(290);/*www . j a v a 2s. com*/ TableColumn removeColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); removeColumn.setText("Remove"); removeColumn.setWidth(70); tableViewer.getTable().addMouseListener(new MouseListener() { @Override public void mouseUp(MouseEvent e) { } @Override public void mouseDown(MouseEvent e) { onRemoveButtonClick(e.x, e.y); } @Override public void mouseDoubleClick(MouseEvent e) { } }); tableViewer.getTable().addListener(SWT.PaintItem, new Listener() { @Override public void handleEvent(Event event) { if (event.index == 1) { Image tmpImage = ContrastUIActivator.getImage("/icons/remove.png"); int tmpWidth = 0; int tmpHeight = 0; int tmpX = 0; int tmpY = 0; tmpWidth = tableViewer.getTable().getColumn(event.index).getWidth(); tmpHeight = ((TableItem) event.item).getBounds().height; tmpX = tmpImage.getBounds().width; tmpX = (tmpWidth / 2 - tmpX / 2); tmpY = tmpImage.getBounds().height; tmpY = (tmpHeight / 2 - tmpY / 2); if (tmpX <= 0) tmpX = event.x; else tmpX += event.x; if (tmpY <= 0) tmpY = event.y; else tmpY += event.y; event.gc.drawImage(tmpImage, tmpX, tmpY); } } }); return tableViewer; }
From source file:com.dtsworkshop.flextools.search.ui.SearchResultPage.java
License:Open Source License
@Override protected void configureTableViewer(TableViewer viewer) { viewer.setUseHashlookup(true); //TODO: What does setUseHashlookup do? viewer.setContentProvider(new ClassContentProvider()); viewer.setLabelProvider(new ClassLabelProvider()); viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { handleDoubleClick(event);// ww w . j av a2 s .c om } }); }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.SwtFactory.java
License:Open Source License
/** * Creates a file list with a browser to open a file dialog. * <p>/* w w w. j a v a2 s . c o m*/ * When a file is added or removed, a selection listener is invoked. * </p> * * @param parent the parent * @param filterNames the filter names * @param fileExtensions the file extensions * @param files a non-null collection of files (can be empty) * @return the tree viewer that displays the selected files */ public static ListWithButtonComposite createFileListViewer(final Composite parent, final String[] filterNames, final String[] fileExtensions, final Collection<File> files) { final ListWithButtonComposite lbc = new ListWithButtonComposite(parent); lbc.setLayoutData(new GridData(GridData.FILL_BOTH)); final TableViewer viewer = lbc.getViewer(); viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { if (element instanceof File) return ((File) element).getAbsolutePath(); return super.getText(element); } }); // ADD button lbc.getAddButton().setText("Add"); lbc.getAddButton().setImage(PetalsImages.INSTANCE.getAdd()); lbc.getAddButton().addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { FileDialog dlg = new FileDialog(parent.getShell(), SWT.MULTI); dlg.setText("Select one or several files"); dlg.setFilterNames(filterNames); dlg.setFilterExtensions(fileExtensions); String path = PreferencesManager.getSavedLocation(); if (path.trim().length() > 0) dlg.setFilterPath(path); String fn = dlg.open(); if (fn == null) return; // Process the files path = dlg.getFilterPath(); PreferencesManager.setSavedLocation(path); File parent = new File(path); for (String filename : dlg.getFileNames()) { File chosenFile = new File(parent, filename); files.add(chosenFile); } viewer.setInput(files); viewer.refresh(); lbc.notifyListeners(); } }); // REMOVE button lbc.getRemoveButton().setText("Remove"); lbc.getRemoveButton().setImage(PetalsImages.INSTANCE.getDelete()); lbc.getRemoveButton().addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Iterator<?> it = ((IStructuredSelection) viewer.getSelection()).iterator(); while (it.hasNext()) { File f = (File) it.next(); files.remove(f); } viewer.setInput(files); viewer.refresh(); lbc.notifyListeners(); } }); return lbc; }
From source file:com.ebmwebsourcing.petals.components.drivers.ComponentConfigurationWizardPage.java
License:Open Source License
@Override public void createControl(Composite parent) { setTitle("Configured Component"); setMessage("Update a Petals component to use one or several shared libraries."); Composite container = new Composite(parent, SWT.NONE); container.setLayout(new GridLayout()); container.setLayoutData(new GridData(GridData.FILL_BOTH)); setControl(container);/*from w ww.j av a2 s .c o m*/ // Select the component's archive Composite subC = new Composite(container, SWT.NONE); GridLayout layout = new GridLayout(3, false); layout.marginWidth = 0; layout.marginHeight = 0; subC.setLayout(layout); subC.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Label l = new Label(subC, SWT.NONE); l.setText("Component's URL:"); l.setToolTipText("The URL of the component's ZIP"); final Text componentUrlText = new Text(subC, SWT.SINGLE | SWT.BORDER); componentUrlText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); componentUrlText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { ComponentConfigurationWizardPage.this.componentUrl = ((Text) e.widget).getText().trim(); validate(); } }); Button browseButton = new Button(subC, SWT.PUSH); browseButton.setText("Browse..."); browseButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { widgetDefaultSelected(e); } @Override public void widgetDefaultSelected(SelectionEvent e) { FileDialog dlg = new FileDialog(getShell(), SWT.SINGLE); dlg.setText("Select a zipped component file"); dlg.setFilterNames(new String[] { "ZIP (*.zip)" }); dlg.setFilterExtensions(new String[] { "*.zip" }); String path = PreferencesManager.getSavedLocation(); if (!StringUtils.isEmpty(path)) { try { File f = new File(path); dlg.setFilterPath(f.getParentFile().getAbsolutePath()); dlg.setFileName(f.getName()); } catch (Exception e1) { // nothing } } String fn = dlg.open(); if (fn != null) { PreferencesManager.setSavedLocation(fn); fn = convertFilePathToUrl(fn); componentUrlText.setText(fn); } } }); // Choose the output location l = new Label(subC, SWT.NONE); l.setText("Output Location:"); l.setToolTipText("The location of the component after configuration"); final Text outputLocationText = new Text(subC, SWT.SINGLE | SWT.BORDER); outputLocationText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); outputLocationText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { ComponentConfigurationWizardPage.this.updatedFileLocation = ((Text) e.widget).getText().trim(); validate(); } }); browseButton = new Button(subC, SWT.PUSH); browseButton.setText("Browse..."); browseButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { widgetDefaultSelected(e); } @Override public void widgetDefaultSelected(SelectionEvent e) { FileDialog dlg = new FileDialog(getShell(), SWT.SINGLE | SWT.SAVE); dlg.setText("Select a zipped component file"); dlg.setFilterNames(new String[] { "ZIP (*.zip)" }); dlg.setFilterExtensions(new String[] { "*.zip" }); // File name String name = null; if (ComponentConfigurationWizardPage.this.componentUrl != null) { int index = Math.max(ComponentConfigurationWizardPage.this.componentUrl.lastIndexOf('/'), ComponentConfigurationWizardPage.this.componentUrl.lastIndexOf('\\')); if (index > 0 && index < ComponentConfigurationWizardPage.this.componentUrl.length() - 1) { name = ComponentConfigurationWizardPage.this.componentUrl.substring(index + 1); name = StringUtils.insertSuffixBeforeFileExtension(name, "--patched"); } } // Save location String path = PreferencesManager.getSavedLocation(); if (!StringUtils.isEmpty(path)) { try { File f = new File(path); dlg.setFilterPath(f.getParentFile().getAbsolutePath()); dlg.setFileName(name == null ? f.getName() : name); } catch (Exception e1) { // nothing } } else if (name != null) { dlg.setFileName(name); } String fn = dlg.open(); if (fn != null) outputLocationText.setText(fn); } }); new Label(subC, SWT.NO_FOCUS); final Button overwriteButton = new Button(subC, SWT.CHECK); overwriteButton.setText("Overwrite"); overwriteButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { widgetDefaultSelected(e); } @Override public void widgetDefaultSelected(SelectionEvent e) { ComponentConfigurationWizardPage.this.overwrite = overwriteButton.getSelection(); validate(); } }); // Add a table to display the shared libraries to add subC = new Composite(container, SWT.NONE); layout = new GridLayout(2, false); layout.marginWidth = 0; layout.marginHeight = 0; layout.marginTop = 18; subC.setLayout(layout); subC.setLayoutData(new GridData(GridData.FILL_BOTH)); l = new Label(subC, SWT.NONE); l.setText("Select or define the shared libraries this component must use."); GridData layoutData = new GridData(); layoutData.horizontalSpan = 2; l.setLayoutData(layoutData); final TableViewer slViewer = new TableViewer(subC, SWT.BORDER | SWT.HIDE_SELECTION | SWT.FULL_SELECTION | SWT.SINGLE); slViewer.setContentProvider(new ArrayContentProvider()); slViewer.setLabelProvider(new ITableLabelProvider() { @Override public void removeListener(ILabelProviderListener listener) { // nothing } @Override public boolean isLabelProperty(Object element, String property) { return false; } @Override public void dispose() { // nothing } @Override public void addListener(ILabelProviderListener listener) { // nothing } @Override public String getColumnText(Object element, int columnIndex) { Object key = ((Map.Entry<?, ?>) element).getKey(); Object value = ((Map.Entry<?, ?>) element).getValue(); String result = ""; ; if (columnIndex == 0) result = (String) key; else if (columnIndex == 1) result = (String) value; return result; } @Override public Image getColumnImage(Object element, int columnIndex) { return null; } }); slViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); slViewer.getTable().setHeaderVisible(true); slViewer.getTable().setLinesVisible(true); TableLayout tlayout = new TableLayout(); tlayout.addColumnData(new ColumnWeightData(85, 300, true)); tlayout.addColumnData(new ColumnWeightData(15, 50, true)); slViewer.getTable().setLayout(tlayout); TableColumn column = new TableColumn(slViewer.getTable(), SWT.LEFT); column.setText(NAME); column = new TableColumn(slViewer.getTable(), SWT.CENTER); column.setText(VERSION); slViewer.setColumnProperties(new String[] { NAME, VERSION }); // Add some buttons Composite buttonsComposite = new Composite(subC, SWT.NONE); layout = new GridLayout(); layout.marginWidth = 0; layout.marginHeight = 0; buttonsComposite.setLayout(layout); buttonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true)); Button addSlFileButton = new Button(buttonsComposite, SWT.PUSH); addSlFileButton.setText("Add a File..."); addSlFileButton.setToolTipText("Select a Shared Library file"); addSlFileButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); Button addSlUrlButton = new Button(buttonsComposite, SWT.PUSH); addSlUrlButton.setText("Add an URL..."); addSlUrlButton.setToolTipText("Add an URL pointing to a Shared Library"); addSlUrlButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); Button specifySlButton = new Button(buttonsComposite, SWT.PUSH); specifySlButton.setText("Specify Manually..."); specifySlButton.setToolTipText("Enter a shared library name and a shared library version manually"); specifySlButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); final Button editButton = new Button(buttonsComposite, SWT.PUSH); editButton.setText("Edit..."); editButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); final Button deleteButton = new Button(buttonsComposite, SWT.PUSH); deleteButton.setText("Delete"); deleteButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); // Button listeners addSlFileButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { openSlFileDialog(slViewer, null); } @Override public void widgetDefaultSelected(SelectionEvent e) { openSlFileDialog(slViewer, null); } }); addSlUrlButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { openSlUrlDialog(slViewer, null); } @Override public void widgetDefaultSelected(SelectionEvent e) { openSlUrlDialog(slViewer, null); } }); specifySlButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { openSlDialog(slViewer, null); } @Override public void widgetDefaultSelected(SelectionEvent e) { openSlDialog(slViewer, null); } }); editButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { widgetDefaultSelected(e); } @Override public void widgetDefaultSelected(SelectionEvent e) { if (!slViewer.getSelection().isEmpty()) { Object o = ((IStructuredSelection) slViewer.getSelection()).getFirstElement(); if (o instanceof Map.Entry<?, ?>) { o = ((Map.Entry<?, ?>) o).getKey(); if (o instanceof String) openSlDialog(slViewer, (String) o); } } } }); deleteButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { widgetDefaultSelected(e); } @Override public void widgetDefaultSelected(SelectionEvent e) { if (!slViewer.getSelection().isEmpty()) { Object o = ((IStructuredSelection) slViewer.getSelection()).getFirstElement(); ComponentConfigurationWizardPage.this.slNameToVersion.remove(o); slViewer.setInput(ComponentConfigurationWizardPage.this.slNameToVersion.entrySet()); slViewer.refresh(); } } }); // Other listeners slViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { deleteButton.setEnabled(true); Object o = ((IStructuredSelection) slViewer.getSelection()).getFirstElement(); if (o instanceof Map.Entry<?, ?>) { o = ((Map.Entry<?, ?>) o).getKey(); boolean disabled = o instanceof File; editButton.setEnabled(!disabled); } } }); setPageComplete(false); }
From source file:com.ebmwebsourcing.petals.services.sa.export.SaExportWizardPage.java
License:Open Source License
public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = 10;//from w w w . j a va 2 s. com layout.marginWidth = 10; container.setLayout(layout); container.setLayoutData(new GridData(GridData.FILL_BOTH)); new Label(container, SWT.NONE).setText("Select the Service Assembly project(s) to export:"); // Project viewer TableViewer viewer = new TableViewer(container, SWT.BORDER | SWT.CHECK); GridData layoutData = new GridData(GridData.FILL_BOTH); layoutData.heightHint = 180; viewer.getTable().setLayoutData(layoutData); viewer.setLabelProvider(new WorkbenchLabelProvider()); viewer.setContentProvider(new ArrayContentProvider()); viewer.setInput(this.saProjects.keySet()); for (TableItem item : viewer.getTable().getItems()) { IProject p = (IProject) item.getData(); if (this.saProjects.get(p)) item.setChecked(true); } viewer.getTable().addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { boolean checked = ((TableItem) event.item).getChecked(); IProject p = (IProject) ((TableItem) event.item).getData(); SaExportWizardPage.this.saProjects.put(p, checked); validate(); } }); // Export mode Label label = new Label(container, SWT.NONE); label.setText("Select the export mode:"); layoutData = new GridData(); layoutData.verticalIndent = 17; label.setLayoutData(layoutData); // Export mode - one per project Button projectModeButton = new Button(container, SWT.RADIO); projectModeButton.setText("Export every selected Service Assembly in its project."); projectModeButton.setToolTipText( "The created archives will be placed at the root of the associated Service Assembly projects."); layoutData = new GridData(); layoutData.verticalIndent = 3; projectModeButton.setLayoutData(layoutData); // Export mode - one per project, in a same directory Button separateModeButton = new Button(container, SWT.RADIO); separateModeButton.setText("Export the Service Assemblies separately, but in a same directory."); separateModeButton.setToolTipText("The created archive will be placed in the selected directory."); Composite subContainer = new Composite(container, SWT.NONE); layout = new GridLayout(3, false); layout.marginWidth = 0; layout.marginHeight = 0; layout.marginLeft = 16; subContainer.setLayout(layout); subContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final Label dirLabel = new Label(subContainer, SWT.NONE); dirLabel.setText("Output directory:"); layoutData = new GridData(); layoutData.widthHint = 90; dirLabel.setLayoutData(layoutData); final Text dirText = new Text(subContainer, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); dirText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); String loc = PetalsServicesPlugin.getDefault().getPreferenceStore().getString(PREF_DIRECTORY_LOC); if (loc.length() != 0) { dirText.setText(loc); this.outputFile = new File(loc); } dirText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { SaExportWizardPage.this.outputFile = new File(dirText.getText()); validate(); } }); final Button browseDirButton = new Button(subContainer, SWT.PUSH); browseDirButton.setText("Browse..."); browseDirButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { widgetDefaultSelected(e); } public void widgetDefaultSelected(SelectionEvent e) { DirectoryDialog dlg = new DirectoryDialog(dirText.getShell()); dlg.setText("Output Directory"); dlg.setMessage("Select the output directory."); if (SaExportWizardPage.this.outputFile != null && SaExportWizardPage.this.outputFile.exists()) dlg.setFilterPath(SaExportWizardPage.this.outputFile.getAbsolutePath()); String loc = dlg.open(); if (loc != null) { dirText.setText(loc); PetalsServicesPlugin.getDefault().getPreferenceStore().setValue(PREF_DIRECTORY_LOC, loc); } } }); // Selection listeners projectModeButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { widgetDefaultSelected(e); } public void widgetDefaultSelected(SelectionEvent e) { dirLabel.setEnabled(false); dirText.setEnabled(false); browseDirButton.setEnabled(false); dirText.setBackground(dirText.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); SaExportWizardPage.this.outputFile = null; SaExportWizardPage.this.exportMode = SaExportMode.IN_PROJECT; validate(); } }); separateModeButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { widgetDefaultSelected(e); } public void widgetDefaultSelected(SelectionEvent e) { dirLabel.setEnabled(true); dirText.setEnabled(true); browseDirButton.setEnabled(true); dirText.setBackground(dirText.getDisplay().getSystemColor(SWT.COLOR_WHITE)); SaExportWizardPage.this.outputFile = new File(dirText.getText()); SaExportWizardPage.this.exportMode = SaExportMode.IN_SAME_LOCATION; validate(); } }); // Last UI details setControl(container); viewer.getTable().setFocus(); projectModeButton.setSelection(true); projectModeButton.notifyListeners(SWT.Selection, new Event()); String msg = getErrorMessage(); if (msg != null) { setErrorMessage(null); setMessage(msg, IMessageProvider.INFORMATION); } }