List of usage examples for org.eclipse.jface.viewers ViewerCell setText
public void setText(String text)
From source file:com.arm.cmsis.pack.ui.tree.AdvisedCellLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { Object element = cell.getElement(); int index = cell.getColumnIndex(); Color clr = columnAdvisor.getBgColor(element, index); if (clr != null) cell.setBackground(clr);/*from w ww . ja v a 2s .c o m*/ else cell.setBackground(null); boolean enabled = columnAdvisor.isEnabled(element, index); switch (columnAdvisor.getCellControlType(element, index)) { case TEXT: cell.setImage(columnAdvisor.getImage(element, index)); case SPIN: case MENU: case COMBO: cell.setText(columnAdvisor.getString(element, index)); if (!enabled) { cell.setForeground(getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY)); } else { cell.setForeground(null); } break; case URL: cell.setImage(columnAdvisor.getImage(element, index)); cell.setText(columnAdvisor.getString(element, index)); cell.setForeground(getDisplay().getSystemColor(SWT.COLOR_LINK_FOREGROUND)); break; default: break; } super.update(cell); }
From source file:com.astra.ses.spell.gui.model.htree.HistoryTreeLabelProvider.java
License:Open Source License
/************************************************************************** * //from ww w .j ava 2 s .c o m *************************************************************************/ @Override public void update(ViewerCell cell) { Object element = cell.getElement(); cell.setText(getText(element)); cell.setBackground(getBackground(element)); cell.setForeground(getForeground(element)); cell.setImage(getImage(element)); cell.setFont(getFont(element)); }
From source file:com.blackducksoftware.integration.eclipseplugin.views.providers.DependencyComponentColumnLabelProvider.java
License:Apache License
@Override public void styleCell(ViewerCell cell) { String[] compChunks = cell.getText().split(":"); cell.setText(String.format("%1$s %2$s ", compChunks[0], compChunks[1])); Display display = Display.getCurrent(); final Color versionColor = decodeHex(display, "#285F8F"); final Color backgroundColor = decodeHex(display, "#fafafa"); final Color borderColor = decodeHex(display, "#dddddd"); final StyleRange versionStyle = new StyleRange(compChunks[0].length() + 1, compChunks[1].length() + 2, versionColor, backgroundColor); versionStyle.borderStyle = SWT.BORDER_SOLID; versionStyle.borderColor = borderColor; int versionHeight = (int) (cell.getFont().getFontData()[0].getHeight() * 0.85); versionStyle.font = FontDescriptor.createFrom(cell.getFont()).setHeight(versionHeight).createFont(display); cell.setStyleRanges(new StyleRange[] { versionStyle }); }
From source file:com.blackducksoftware.integration.eclipseplugin.views.providers.DependencyNumVulnColumnLabelProvider.java
License:Apache License
@Override public void styleCell(ViewerCell cell) { if (cell.getText().equals(VALUE_UNKNOWN)) { cell.setText(""); return;/*from ww w . ja v a 2s. c o m*/ } String[] vulnChunks = cell.getText().split(":"); cell.setFont(JFaceResources.getTextFont()); Display display = Display.getCurrent(); final String noVulns = " 0 "; final Color textColor = display.getSystemColor(SWT.COLOR_WHITE); final Color highColor = decodeHex(display, "#b52b24"); final Color mediumColor = decodeHex(display, "#eca4a0"); final Color lowColor = decodeHex(display, "#999999"); final Color invisible = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); final Color[] vulnColors = new Color[] { highColor, mediumColor, lowColor }; StyleRange[] styleRanges = new StyleRange[vulnChunks.length]; int lastLabelEnd = 0; cell.setText(String.format("%1$-5s %2$-5s %3$-5s", StringUtils.center(vulnChunks[0], 5), StringUtils.center(vulnChunks[1], 5), StringUtils.center(vulnChunks[2], 5))); for (int i = 0; i < vulnChunks.length; i++) { int labelStart = cell.getText().indexOf(vulnChunks[i], lastLabelEnd); int labelSize = vulnChunks[i].length(); if (vulnChunks[i].equals(noVulns)) { styleRanges[i] = new StyleRange(labelStart, labelSize, invisible, invisible); } else { styleRanges[i] = new StyleRange(labelStart, labelSize, textColor, vulnColors[i]); } lastLabelEnd = labelStart + labelSize; } cell.setStyleRanges(styleRanges); }
From source file:com.blackducksoftware.integration.eclipseplugin.views.providers.DependencyTreeViewLabelProvider.java
License:Apache License
@Override public void update(ViewerCell cell) { super.update(cell); cell.setText(getText(cell.getElement())); cell.setImage(getImage(cell.getElement())); styleCell(cell);//from ww w .ja v a 2 s . c o m }
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 a2s .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/* w w w .ja va 2 s. c om*/ * * @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.cloudbees.eclipse.dev.ui.views.build.BuildHistoryView.java
License:Open Source License
@Override public void createPartControl(final Composite parent) { initImages();/* w w w .java2s. c o m*/ this.table = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION /*SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL*/); //Tree tree = viewer.getTree(); //tree.setHeaderVisible(true); //table.getTable().setLinesVisible(true); this.table.getTable().setHeaderVisible(true); TableViewerColumn statusCol = createColumn("S", 22, BuildSorter.STATE, new CellLabelProvider() { @Override public void update(final ViewerCell cell) { JenkinsBuild build = (JenkinsBuild) cell.getViewerRow().getElement(); String key = build.result; /* ImageData[] imageDatas = new ImageLoader().load(new FileInputStream("myAnimated.gif")); Image[] images = new Image[imageDatas.length]; for (int n = 0; n < imageDatas.length; n++) { // images[n] = new Image(myTable.getDislay(), imageDatas[n]); } */ // if (job.color != null && job.color.contains("_")) { // key = job.color.substring(0, job.color.indexOf("_")); // } Image img = BuildHistoryView.this.stateIcons.get(key); if (img != null) { cell.setText(""); cell.setImage(img); } else { cell.setImage(null); cell.setText(build.result); } } }); statusCol.getColumn().setToolTipText("Status"); //TODO i18n TableViewerColumn namecol = createColumn("Build", 50, BuildSorter.BUILD, new CellLabelProvider() { @Override public void update(final ViewerCell cell) { JenkinsBuild build = (JenkinsBuild) cell.getViewerRow().getElement(); String val; try { if (build.building) { val = "building"; } else { val = build.number.toString(); } } catch (Exception e) { val = ""; } cell.setText(val); } }); createColumn("When", 100, BuildSorter.TIME, new CellLabelProvider() { @Override public void update(final ViewerCell cell) { JenkinsBuild build = (JenkinsBuild) cell.getViewerRow().getElement(); if (build.timestamp != null) { try { cell.setText( Utils.humanReadableTime(System.currentTimeMillis() - build.timestamp) + " ago"); } catch (Exception e) { cell.setText(""); } } else { cell.setText(""); } cell.setImage(null); } }); createColumn("Build Duration", 100, BuildSorter.DURATION, new CellLabelProvider() { @Override public void update(final ViewerCell cell) { JenkinsBuild build = (JenkinsBuild) cell.getViewerRow().getElement(); if (build.duration != null) { try { cell.setText(Utils.humanReadableTime(build.duration)); } catch (Throwable t) { cell.setText(""); } } else { cell.setText(""); } } }); createColumn("Tests", 200, BuildSorter.TESTS, new CellLabelProvider() { @Override public void update(final ViewerCell cell) { JenkinsBuild build = (JenkinsBuild) cell.getViewerRow().getElement(); try { long total = 0; long failed = 0; long skipped = 0; for (com.cloudbees.eclipse.core.jenkins.api.JenkinsBuild.Action action : build.actions) { if ("testReport".equalsIgnoreCase(action.urlName)) { total += action.totalCount; failed += action.failCount; skipped += action.skipCount; } } if (total > 0 || failed > 0 || skipped > 0) { String val = "Passed: " + (total - failed - skipped); if (failed > 0) { val += ", failed: " + failed; } if (skipped > 0) { val += ", skipped: " + skipped; } cell.setText(val); } else { cell.setText(""); } } catch (Throwable t) { cell.setText(""); } } }); createColumn("Cause", 250, BuildSorter.CAUSE, new CellLabelProvider() { @Override public void update(final ViewerCell cell) { JenkinsBuild build = (JenkinsBuild) cell.getViewerRow().getElement(); String val = null; try { for (com.cloudbees.eclipse.core.jenkins.api.JenkinsBuild.Action action : build.actions) { if (action.causes != null && action.causes.length > 0) { val = action.causes[0].shortDescription; break; } } if (val == null) { val = ""; } cell.setText(val); } catch (Throwable t) { cell.setText(""); } } }); this.contentProvider = new BuildHistoryContentProvider(); this.table.setContentProvider(this.contentProvider); BuildSorter sorter = new BuildSorter(BuildSorter.BUILD); sorter.setDirection(SWT.UP); this.table.setSorter(sorter); this.table.setInput(getViewSite()); /* table.addFilter(new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { return true; } });*/ this.table.addOpenListener(new IOpenListener() { public void open(final OpenEvent event) { ISelection sel = event.getSelection(); if (sel instanceof IStructuredSelection) { Object el = ((IStructuredSelection) sel).getFirstElement(); if (el instanceof JenkinsBuild) { CloudBeesDevUiPlugin.getDefault().showBuild(((JenkinsBuild) el)); } } } }); this.table.getTable().setSortColumn(namecol.getColumn()); this.table.getTable().setSortDirection(SWT.DOWN); makeActions(); contributeToActionBars(); MenuManager popupMenu = new MenuManager(); popupMenu.add(this.actionOpenBuild); popupMenu.add(this.actionOpenLog); popupMenu.add(new Separator("cloudActions")); popupMenu.add(this.actionOpenBuildInBrowser); popupMenu.add(this.actionInvokeBuild); popupMenu.add(new Separator("reloadActions")); popupMenu.add(this.actionReloadJobs); Menu menu = popupMenu.createContextMenu(this.table.getTable()); this.table.getTable().setMenu(menu); this.table.addPostSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { StructuredSelection sel = (StructuredSelection) event.getSelection(); BuildHistoryView.this.selectedBuild = sel.getFirstElement(); boolean enable = BuildHistoryView.this.selectedBuild != null; BuildHistoryView.this.actionInvokeBuild.setJob(BuildHistoryView.this.selectedBuild); BuildHistoryView.this.actionOpenBuildInBrowser.setEnabled(enable); BuildHistoryView.this.actionOpenBuild.setBuild(BuildHistoryView.this.selectedBuild); BuildHistoryView.this.actionOpenLog.setBuild(BuildHistoryView.this.selectedBuild); getViewSite().getActionBars().getToolBarManager().update(true); } }); this.jenkinsChangeListener = new CBRemoteChangeAdapter() { public void activeJobHistoryChanged(final JenkinsJobAndBuildsResponse newView) { PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { BuildHistoryView.this.setInput(newView); } }); } }; CloudBeesUIPlugin.getDefault().addCBRemoteChangeListener(this.jenkinsChangeListener); }
From source file:com.cloudbees.eclipse.dev.ui.views.jobs.JobsView.java
License:Open Source License
private void initColumns() { TreeViewerColumn namecol = createColumn("Job", 250, JobSorter.JOB, new ColumnLabelProvider() { @Override/*from ww w . jav a 2 s . c o m*/ public void update(final ViewerCell cell) { Object el = cell.getViewerRow().getElement(); if (el instanceof PendingUpdateAdapter) { PendingUpdateAdapter uel = (PendingUpdateAdapter) el; cell.setText(uel.getLabel(null)); cell.setImage(null); return; } JobViewGeneric vg = ((JobHolder) cell.getViewerRow().getElement()).job; if (vg instanceof JenkinsJobsResponse.Job) { JenkinsJobsResponse.Job job = (Job) vg; String val = job.getDisplayName(); if (job.inQueue != null && job.inQueue) { val = val + " (in queue)"; } else if (job.color != null && job.color.indexOf('_') > 0) { val = val + " (running)"; } cell.setText(val); String key = job.color; if (job.color != null && job.color.contains("_")) { key = job.color.substring(0, job.color.indexOf("_")); } // Assuming for now that these are all folders as thers's no API to tell the difference if (job.color == null) { key = "folder"; } Image img = JobsView.this.stateIcons.get(key); if (img != null) { cell.setImage(img); } else if (job.color != null) { cell.setText(val + "[" + job.color + "]"); } } if (vg instanceof View) { cell.setImage(CloudBeesDevUiPlugin.getImage(CBDEVImages.IMG_VIEWR2)); cell.setText(vg.getName()); } } }); createColumn("Build stability", 250, JobSorter.BUILD_STABILITY, new ColumnLabelProvider() { @Override public void update(final ViewerCell cell) { Object element = getJob(cell.getViewerRow().getElement()); if ((!(element instanceof JobViewGeneric)) || (element instanceof JobViewGeneric) && ((JobViewGeneric) element).isFolderOrView()) { cell.setText(""); cell.setImage(null); return; } JenkinsJobsResponse.Job job = (Job) element; cell.setText(""); cell.setImage(null); try { if (job.healthReport != null) { for (int h = 0; h < job.healthReport.length; h++) { String icon = job.healthReport[h].iconUrl; String desc = job.healthReport[h].description; String matchStr = "Build stability: "; if (desc != null && desc.startsWith(matchStr)) { cell.setText(" " + desc.substring(matchStr.length())); cell.setImage(CloudBeesDevUiPlugin .getImage(CBDEVImages.IMG_HEALTH_PREFIX + CBDEVImages.IMG_16 + icon)); } } } } catch (Throwable t) { t.printStackTrace(); } } }); createColumn("Last build", 150, JobSorter.LAST_BUILD, new ColumnLabelProvider() { @Override public void update(final ViewerCell cell) { Object element = getJob(cell.getViewerRow().getElement()); if ((!(element instanceof JobViewGeneric)) || (element instanceof JobViewGeneric) && ((JobViewGeneric) element).isFolderOrView()) { cell.setText(""); cell.setImage(null); return; } JenkinsJobsResponse.Job job = (Job) element; try { cell.setText(JobsView.this.formatBuildInfo(job.lastBuild)); } catch (Throwable t) { cell.setText(""); } } }); createColumn("Last success", 150, JobSorter.LAST_SUCCESS, new ColumnLabelProvider() { @Override public void update(final ViewerCell cell) { Object element = getJob(cell.getViewerRow().getElement()); if ((!(element instanceof JobViewGeneric)) || (element instanceof JobViewGeneric) && ((JobViewGeneric) element).isFolderOrView()) { cell.setText(""); cell.setImage(null); return; } JenkinsJobsResponse.Job job = (Job) element; try { cell.setText(JobsView.this.formatBuildInfo(job.lastSuccessfulBuild)); } catch (Throwable t) { cell.setText(""); } } }); createColumn("Last failure", 150, JobSorter.LAST_FAILURE, new ColumnLabelProvider() { @Override public void update(final ViewerCell cell) { Object element = getJob(cell.getViewerRow().getElement()); if ((!(element instanceof JobViewGeneric)) || (element instanceof JobViewGeneric) && ((JobViewGeneric) element).isFolderOrView()) { cell.setText(""); cell.setImage(null); return; } JenkinsJobsResponse.Job job = (Job) element; try { cell.setText(JobsView.this.formatBuildInfo(job.lastFailedBuild)); } catch (Throwable t) { cell.setText(""); } } }); }
From source file:com.cloudbees.eclipse.run.ui.wizards.ClickStartComposite.java
License:Open Source License
private void init() { GridLayout layout = new GridLayout(1, false); layout.marginHeight = 0;/* www .j ava 2 s . c om*/ layout.marginWidth = 0; layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.marginTop = 10; setLayout(layout); GridData d1 = new GridData(); d1.horizontalSpan = 1; d1.grabExcessHorizontalSpace = true; d1.grabExcessVerticalSpace = true; d1.horizontalAlignment = SWT.FILL; d1.verticalAlignment = SWT.FILL; setLayoutData(d1); Group group = new Group(this, SWT.FILL); group.setText(GROUP_LABEL); GridLayout grl = new GridLayout(1, false); grl.horizontalSpacing = 0; grl.verticalSpacing = 0; grl.marginHeight = 0; grl.marginWidth = 0; grl.marginTop = 4; group.setLayout(grl); GridData data = new GridData(); data.horizontalSpan = 1; data.grabExcessHorizontalSpace = true; data.grabExcessVerticalSpace = true; data.horizontalAlignment = SWT.FILL; data.verticalAlignment = SWT.FILL; group.setLayoutData(data); /* this.addTemplateCheck = new Button(group, SWT.CHECK); this.addTemplateCheck.setText(FORGE_REPO_CHECK_LABEL); this.addTemplateCheck.setSelection(false); this.addTemplateCheck.setLayoutData(data); this.addTemplateCheck.addSelectionListener(new MakeForgeRepoSelectionListener()); data = new GridData(); data.verticalAlignment = SWT.CENTER; this.templateLabel = new Label(group, SWT.NULL); this.templateLabel.setLayoutData(data); this.templateLabel.setText("Template:"); this.templateLabel.setEnabled(false); data = new GridData(); data.grabExcessHorizontalSpace = true; data.horizontalAlignment = SWT.FILL; this.templateCombo = new Combo(group, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY); this.templateCombo.setLayoutData(data); this.templateCombo.setEnabled(false); this.repoComboViewer = new ComboViewer(this.templateCombo); this.repoComboViewer.setLabelProvider(new TemplateLabelProvider()); this.repoComboViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { ISelection selection = ClickStartComposite.this.repoComboViewer.getSelection(); if (selection instanceof StructuredSelection) { ClickStartComposite.this.selectedTemplate = (ClickStartTemplate) ((StructuredSelection) selection) .getFirstElement(); } validate(); } });*/ /* Composite compositeJenkinsInstances = new Composite(group, SWT.NONE); compositeJenkinsInstances.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); GridLayout gl_compositeJenkinsInstances = new GridLayout(2, false); gl_compositeJenkinsInstances.marginWidth = 0; compositeJenkinsInstances.setLayout(gl_compositeJenkinsInstances); */ Composite compositeTable = new Composite(group, SWT.NONE); compositeTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); GridLayout gl_compositeTable = new GridLayout(1, false); gl_compositeTable.marginHeight = 0; gl_compositeTable.marginWidth = 0; compositeTable.setLayout(gl_compositeTable); v = new TableViewer(compositeTable, SWT.BORDER | SWT.FULL_SELECTION); v.getTable().setLinesVisible(true); v.getTable().setHeaderVisible(true); v.setContentProvider(templateProvider); v.setInput(""); v.getTable().setLayout(new GridLayout(1, false)); GridData vgd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); v.getTable().setLayoutData(vgd); ColumnViewerToolTipSupport.enableFor(v, ToolTip.NO_RECREATE); CellLabelProvider labelProvider = new CellLabelProvider() { public String getToolTipText(Object element) { ClickStartTemplate t = (ClickStartTemplate) element; return t.description; } public Point getToolTipShift(Object object) { return new Point(5, 5); } public int getToolTipDisplayDelayTime(Object object) { return 200; } public int getToolTipTimeDisplayed(Object object) { return 10000; } public void update(ViewerCell cell) { int idx = cell.getColumnIndex(); ClickStartTemplate t = (ClickStartTemplate) cell.getElement(); if (idx == 0) { cell.setText(t.name); } else if (idx == 1) { String comps = ""; for (int i = 0; i < t.components.length; i++) { comps = comps + t.components[i].name; if (i < t.components.length - 1) { comps = comps + ", "; } } cell.setText(comps); } } }; /* this.table = new Table(compositeTable, SWT.BORDER | SWT.FULL_SELECTION); this.table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); this.table.setHeaderVisible(true); this.table.setLinesVisible(true); */ v.getTable().addSelectionListener(new SelectionListener() { public void widgetSelected(final SelectionEvent e) { selectedTemplate = (ClickStartTemplate) e.item.getData(); ClickStartComposite.this.fireTemplateChanged(); } public void widgetDefaultSelected(final SelectionEvent e) { selectedTemplate = (ClickStartTemplate) e.item.getData(); ClickStartComposite.this.fireTemplateChanged(); } }); //ColumnViewerToolTipSupport TableViewerColumn tblclmnLabel = new TableViewerColumn(v, SWT.NONE); tblclmnLabel.getColumn().setWidth(300); tblclmnLabel.getColumn().setText("Template");//TODO i18n tblclmnLabel.setLabelProvider(labelProvider); TableViewerColumn tblclmnUrl = new TableViewerColumn(v, SWT.NONE); tblclmnUrl.getColumn().setWidth(800); tblclmnUrl.getColumn().setText("Components");//TODO i18n tblclmnUrl.setLabelProvider(labelProvider); loadData(); //Group group2 = new Group(this, SWT.NONE); //group2.setText(""); //group2.setLayout(ld2); GridData data2 = new GridData(); data2.horizontalSpan = 1; data2.grabExcessHorizontalSpace = true; //data2.grabExcessVerticalSpace = true; data2.horizontalAlignment = SWT.FILL; //data2.verticalAlignment = SWT.FILL; //group2.setLayoutData(data2); browser = new Browser(this, SWT.NONE); //browser.getVerticalBar().setVisible(false); //browser.getHorizontalBar().setVisible(false); GridLayout ld2 = new GridLayout(2, true); ld2.horizontalSpacing = 0; ld2.verticalSpacing = 0; ld2.marginHeight = 0; ld2.marginWidth = 0; GridData gd2 = new GridData(SWT.FILL, SWT.FILL); gd2.heightHint = 50; gd2.horizontalSpan = 1; gd2.grabExcessHorizontalSpace = true; gd2.grabExcessVerticalSpace = false; gd2.horizontalAlignment = SWT.FILL; browser.setLayout(ld2); browser.setLayoutData(gd2); Color bg = this.getBackground(); bgStr = "rgb(" + bg.getRed() + "," + bg.getGreen() + "," + bg.getBlue() + ")"; browser.setText("<html><head><style>body{background-color:" + bgStr + ";margin:0px;padding:0px;width:100%;}</style></head><body style='overflow:hidden;'></body></html>"); //shell.open(); //browser.setUrl("https://google.com"); browser.addLocationListener(new LocationListener() { @Override public void changing(LocationEvent event) { String url = event.location; try { if (url != null && url.startsWith("http")) { event.doit = false; PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(url)); } } catch (PartInitException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } } @Override public void changed(LocationEvent event) { //event.doit = false; } }); v.getTable().setFocus(); /* getParent().setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED)); group.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_CYAN)); v.getTable().setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GREEN)); browser.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_YELLOW)); */}