diff options
author | rescobar | 2010-07-20 20:54:53 +0000 |
---|---|---|
committer | rescobar | 2010-07-20 20:54:53 +0000 |
commit | cd8503bd2a67b2fbcb5daceb02b7ad1089eb525e (patch) | |
tree | 5ccbb5ab8d149dd0b77425a3df0c9a2184d3f47e /plugins/org.eclipse.osee.ote.ui.define | |
parent | a88b295f5a066c21fce3aefc406d1e922ca44733 (diff) | |
download | org.eclipse.osee-cd8503bd2a67b2fbcb5daceb02b7ad1089eb525e.tar.gz org.eclipse.osee-cd8503bd2a67b2fbcb5daceb02b7ad1089eb525e.tar.xz org.eclipse.osee-cd8503bd2a67b2fbcb5daceb02b7ad1089eb525e.zip |
Refactored to use Displays class
Diffstat (limited to 'plugins/org.eclipse.osee.ote.ui.define')
11 files changed, 1588 insertions, 1574 deletions
diff --git a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/dialogs/ReportsDialog.java b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/dialogs/ReportsDialog.java index a6816c8b2ae..88f30d85277 100644 --- a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/dialogs/ReportsDialog.java +++ b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/dialogs/ReportsDialog.java @@ -38,6 +38,7 @@ import org.eclipse.osee.framework.core.exception.OseeStateException; import org.eclipse.osee.framework.jdk.core.type.Pair;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.osee.framework.ui.swt.Widgets;
import org.eclipse.osee.ote.define.jobs.RemoteResourceRequestJob;
@@ -61,7 +62,6 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
@@ -71,446 +71,449 @@ import org.eclipse.swt.widgets.Text; * @author Roberto E. Escobar
*/
public class ReportsDialog extends TitleAreaDialog {
- private static final Image MESSAGE_IMAGE = ImageManager.getImage(OteDefineImage.COMMIT_WIZ);
- private static final Image TITLE_BAR_IMAGE = ImageManager.getImage(OteDefineImage.COMMIT);
-
- private static final String MESSAGE_TITLE = "Select a report";
- private static final String TITLE_BAR_TEXT = "OSEE Test Run Reports";
- private static final String MESSAGE = "The preview window displays an example of the selected report.";
- private static final String REPORT_SELECTION_TITLE = "Select a Report";
- private static final String PREVIEW_TITLE = "Preview";
- private static final String FORMAT_TITLE = "Select a Format";
- private static final String REPORT_DESCRIPTION = "Report Description";
- private static final String PREVIEW_DESCRIPTION = "Enter Preview Size";
-
- private static final String REPORT_STORE_ID = ReportsDialog.class.getName() + ".reportId";
- private static final String FORMAT_STORE_ID = ReportsDialog.class.getName() + ".formatId";
- private static final String PREVIEW_SIZE_STORE_ID = ReportsDialog.class.getName() + ".previewSize";
-
- private static final int DEFAULT_PREVIEW_SIZE = 5;
-
- private PreviewPanel previewPanel;
- private org.eclipse.osee.ote.ui.define.panels.ListSelectionPanel listSelectionPanel;
- private SelectionChangedListener selectionChangedListener;
- private Text descriptionArea;
- private Text previewSizeArea;
- private String selectedReportId;
- private OutputFormat selectedReportFormat;
- private final List<IFile> filesToDelete;
- private Map<OutputFormat, Button> formatButtons;
-
- public ReportsDialog(Shell parent) {
- super(parent);
- this.filesToDelete = new ArrayList<IFile>();
- setShellStyle(SWT.SHELL_TRIM);
- }
-
- @Override
- protected Control createButtonBar(Composite parent) {
- Label separator = new Label(parent, SWT.HORIZONTAL | SWT.SEPARATOR);
- separator.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
- return super.createButtonBar(parent);
- }
-
- /*
- * @see Dialog#createDialogArea(Composite)
- */
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite content = (Composite) super.createDialogArea(parent);
-
- Composite composite = new Composite(content, SWT.NONE);
- composite.setLayout(new GridLayout());
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- composite.setFont(parent.getFont());
-
- SashForm sash = new SashForm(composite, SWT.HORIZONTAL);
- sash.setLayout(new GridLayout());
- sash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- sash.setFont(parent.getFont());
-
- createReportSelectionArea(sash);
-
- Composite panel = new Composite(sash, SWT.NONE);
- GridLayout gL1 = new GridLayout();
- gL1.marginHeight = 0;
- gL1.marginWidth = 0;
- panel.setLayout(gL1);
- panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- createFormatAndDescriptionArea(panel);
- createPreviewArea(panel);
- sash.setWeights(new int[] {1, 2});
-
- setTitle(MESSAGE_TITLE);
- setTitleImage(MESSAGE_IMAGE);
- setMessage(MESSAGE);
- getShell().setText(TITLE_BAR_TEXT);
- getShell().setImage(TITLE_BAR_IMAGE);
- attachListeners();
- restoreDialog();
- return sash;
- }
-
- private void restoreDialog() {
- IDialogSettings settings = OteUiDefinePlugin.getInstance().getDialogSettings();
- if (settings != null) {
- String reportSelected = settings.get(REPORT_STORE_ID);
- String format = settings.get(FORMAT_STORE_ID);
-
- int value = 0;
- try {
- value = settings.getInt(PREVIEW_SIZE_STORE_ID);
- } catch (Exception ex) {
- value = DEFAULT_PREVIEW_SIZE;
- }
- clamp(previewSizeArea, value);
-
- OutputFormat outputFormat = OutputFormat.HTML;
- int index = 0;
- if (Strings.isValid(reportSelected) && Strings.isValid(format)) {
- Pair<String, String> pair = ExtensionDefinedReports.getInstance().getIdAndName(reportSelected);
- index = listSelectionPanel.indexOf(pair);
- outputFormat = OutputFormat.fromString(format);
- }
- if (index > -1) {
- listSelectionPanel.setSelection(index);
- }
- setReportFormat(outputFormat);
- for (OutputFormat key : formatButtons.keySet()) {
- Button button = formatButtons.get(key);
- button.setSelection(key.equals(outputFormat));
- }
- }
- }
-
- private void saveDialog() {
- IDialogSettings settings = OteUiDefinePlugin.getInstance().getDialogSettings();
- if (settings != null) {
- String reportSelected = getReportSelected();
- String format = getReportFormat();
- int previewSize = getPreviewSize();
- settings.put(REPORT_STORE_ID, reportSelected);
- settings.put(FORMAT_STORE_ID, format);
- settings.put(PREVIEW_SIZE_STORE_ID, previewSize);
- }
- }
-
- @Override
- protected void okPressed() {
- saveDialog();
- cleanUp(filesToDelete);
- super.okPressed();
- }
-
- private void createReportSelectionArea(Composite parent) {
- Group composite = new Group(parent, SWT.NONE);
- composite.setLayout(new GridLayout());
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- composite.setFont(parent.getFont());
- composite.setText(REPORT_SELECTION_TITLE);
-
- listSelectionPanel = new ListSelectionPanel(composite, SWT.NONE, 300, 300, new ListLabelProvider());
- listSelectionPanel.setSorter(new ViewerSorter() {
-
- @Override
- @SuppressWarnings("unchecked")
- public int compare(Viewer viewer, Object o1, Object o2) {
- Pair<String, String> pair1 = (Pair<String, String>) o1;
- Pair<String, String> pair2 = (Pair<String, String>) o2;
- return getComparator().compare(pair1.getSecond(), pair2.getSecond());
- }
-
- });
- Pair<String, String>[] reportNames = ExtensionDefinedReports.getInstance().getIdsAndNames();
- listSelectionPanel.setInput(reportNames);
- listSelectionPanel.setSelection(0);
- }
-
- private void createFormatAndDescriptionArea(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayout gL = new GridLayout(2, false);
- gL.marginHeight = 0;
- gL.marginWidth = 0;
- composite.setLayout(gL);
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- createFormatArea(composite);
-
- Composite panel = new Composite(composite, SWT.NONE);
- GridLayout gL1 = new GridLayout();
- gL1.marginHeight = 0;
- gL1.marginWidth = 0;
- panel.setLayout(gL1);
- panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-
- createDescriptionArea(panel);
- createPreviewSizeArea(panel);
- }
-
- private void createPreviewSizeArea(Composite parent) {
- Group group = new Group(parent, SWT.NONE);
- group.setLayout(new GridLayout(2, false));
- group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- group.setFont(parent.getFont());
- group.setText(PREVIEW_DESCRIPTION);
-
- previewSizeArea = new Text(group, SWT.SINGLE | SWT.BORDER);
- previewSizeArea.setTextLimit(2);
- GridData gd = new GridData(SWT.RIGHT, SWT.FILL, false, false);
- gd.heightHint = convertHeightInCharsToPixels(1);
- gd.widthHint = convertWidthInCharsToPixels(4);
- previewSizeArea.setLayoutData(gd);
- new Widgets.IntegerTextEntryHandler(previewSizeArea, false, 2) {
- @Override
- public void applyValue(long value) {
- clamp(previewSizeArea, value);
- }
- };
-
- Label label = new Label(group, SWT.NONE);
- label.setText("[ 0-10 ]");
- label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- }
-
- private void clamp(Text text, long value) {
- if (value < 0) {
- previewSizeArea.setText(Integer.toString(0));
- }
- if (value > 10) {
- previewSizeArea.setText(Integer.toString(10));
- }
- }
-
- private void createDescriptionArea(Composite parent) {
- Group group = new Group(parent, SWT.NONE);
- group.setLayout(new GridLayout());
- group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- group.setFont(parent.getFont());
- group.setText(REPORT_DESCRIPTION);
-
- descriptionArea = new Text(group, SWT.WRAP | SWT.MULTI);
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
- gd.heightHint = 100;
- gd.widthHint = 100;
- descriptionArea.setLayoutData(gd);
- descriptionArea.setEditable(false);
- }
-
- private void createFormatArea(Composite parent) {
- Group group = new Group(parent, SWT.NONE);
- group.setLayout(new GridLayout());
- group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
- group.setFont(parent.getFont());
- group.setText(FORMAT_TITLE);
-
- this.formatButtons = new HashMap<OutputFormat, Button>();
- for (OutputFormat format : OutputFormat.values()) {
- Button button = new Button(group, SWT.RADIO);
- button.setText(format.name());
- button.setData(format);
- if (format.equals(OutputFormat.HTML)) {
- button.setSelection(true);
- }
- button.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- Button button = (Button) e.getSource();
- if (button.getSelection() != false) {
- setReportFormat((OutputFormat) button.getData());
- }
- }
- });
- formatButtons.put(format, button);
- }
- }
-
- private void createPreviewArea(Composite parent) {
- Group group = new Group(parent, SWT.NONE);
- group.setLayout(new GridLayout());
- group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- group.setFont(parent.getFont());
- group.setText(PREVIEW_TITLE);
- previewPanel = new PreviewPanel(group, SWT.NONE);
- }
-
- private void attachListeners() {
- listSelectionPanel.addDoubleClickListener(new IDoubleClickListener() {
- @SuppressWarnings("unchecked")
- public void doubleClick(DoubleClickEvent event) {
- IStructuredSelection selection = (IStructuredSelection) event.getSelection();
- if (selection != null) {
- Pair<String, String> item = (Pair<String, String>) selection.getFirstElement();
- if (item != null) {
- selectedReportId = item.getFirst();
- }
- }
- okPressed();
- }
- });
-
- selectionChangedListener = new SelectionChangedListener();
- listSelectionPanel.addSelectionChangedListener(selectionChangedListener);
- }
-
- public String getReportSelected() {
- return selectedReportId;
- }
-
- public String getReportFormat() {
- return selectedReportFormat.name();
- }
-
- private void setReportFormat(OutputFormat reportFormat) {
- this.selectedReportFormat = reportFormat;
- selectionChangedListener.selectionChanged(null);
- }
-
- private PanelEnum asPanelEnum(OutputFormat format) {
- PanelEnum toReturn = PanelEnum.DEFAULT;
- switch (format) {
- case HTML:
- case PDF:
- case EXCEL:
- case RTF:
- toReturn = PanelEnum.BROWSER;
- break;
- default:
- toReturn = PanelEnum.DEFAULT;
- break;
- }
- return toReturn;
- }
-
- private void updatePanel(final PanelEnum panelId, final URI uri, final String description, final List<IFile> oldIFiles) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- previewPanel.updatePreview(panelId, uri);
- previewPanel.setDisplay(panelId);
- descriptionArea.setText(description);
- }
- });
- cleanUp(oldIFiles);
- }
-
- private int getPreviewSize() {
- int toReturn = DEFAULT_PREVIEW_SIZE;
- String value = previewSizeArea.getText();
- try {
- toReturn = Integer.parseInt(value);
- } catch (Exception ex) {
- toReturn = DEFAULT_PREVIEW_SIZE;
- updatePreviewSizeValue(toReturn);
- }
- return toReturn;
- }
-
- private void updatePreviewSizeValue(final int value) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- previewSizeArea.setText(Integer.toString(value));
- }
- });
- }
-
- private void generatePreview(final OutputFormat outputFormat, final String reportId, final ITestRunReport report) throws URISyntaxException, OseeStateException {
- String urlRequest = HttpReportRequest.getUrl(reportId, outputFormat.name(), "local", getPreviewSize());
- String fileName = OutputFactory.getOutputFilename(outputFormat, reportId);
- switch (outputFormat) {
- case HTML:
- updatePanel(asPanelEnum(outputFormat), new URI(urlRequest), report.getDescription(), filesToDelete);
- break;
- default:
- remoteFileToLocal(outputFormat, urlRequest, fileName, report);
- break;
- }
- }
-
- private void remoteFileToLocal(final OutputFormat outputFormat, final String urlRequest, final String fileName, final ITestRunReport report) {
- RemoteResourceRequestJob requestJob = new RemoteResourceRequestJob(urlRequest, fileName);
- requestJob.addJobChangeListener(new PreviewUpdateJobChangeListener(report, outputFormat));
- requestJob.getDownloadedFile();
- requestJob.schedule();
- }
-
- private final class SelectionChangedListener implements ISelectionChangedListener {
- @SuppressWarnings("unchecked")
- public void selectionChanged(SelectionChangedEvent event) {
- IStructuredSelection selection = listSelectionPanel.getSelection();
- if (selection != null) {
- Pair<String, String> item = (Pair<String, String>) selection.getFirstElement();
- if (item != null) {
- ITestRunReport report = ExtensionDefinedReports.getInstance().getReportGenerator(item.getFirst());
- if (report != null) {
- selectedReportId = item.getFirst();
- try {
- generatePreview(selectedReportFormat, selectedReportId, report);
- } catch (Exception ex) {
- OseeLog.log(OteUiDefinePlugin.class, Level.SEVERE, ex);
- }
- }
- }
- }
- }
- }
-
- private final class ListLabelProvider extends LabelProvider {
-
- @SuppressWarnings("unchecked")
- @Override
- public Image getImage(Object element) {
- Image toReturn = null;
- if (element instanceof Pair) {
- toReturn = ExtensionDefinedReports.getInstance().getImage(((Pair<String, String>) element).getFirst());
- }
- return toReturn;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public String getText(Object element) {
- if (element instanceof Pair) {
- return ((Pair<String, String>) element).getSecond();
- }
- return super.getText(element);
- }
- }
-
- private final class PreviewUpdateJobChangeListener extends JobChangeAdapter {
- private final ITestRunReport report;
- private final OutputFormat format;
-
- private PreviewUpdateJobChangeListener(ITestRunReport report, OutputFormat format) {
- this.report = report;
- this.format = format;
- }
-
- @Override
- public void done(IJobChangeEvent event) {
- IStatus status = event.getResult();
- if (status.equals(Status.OK_STATUS) || status.getCode() == Status.OK) {
- IFile iFile = ((RemoteResourceRequestJob) event.getJob()).getDownloadedFile();
- if (iFile != null) {
- updatePanel(asPanelEnum(format), iFile.getLocationURI(), report.getDescription(), filesToDelete);
- filesToDelete.add(iFile);
- }
- }
- }
- }
-
- private void cleanUp(final List<IFile> iFiles) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- for (IFile iFile : iFiles) {
- if (iFile != null && iFile.exists()) {
- try {
- iFile.delete(true, new NullProgressMonitor());
- filesToDelete.remove(iFile);
- } catch (CoreException ex) {
- // Do Nothing
- }
- }
- }
- }
- });
- }
+ private static final Image MESSAGE_IMAGE = ImageManager.getImage(OteDefineImage.COMMIT_WIZ);
+ private static final Image TITLE_BAR_IMAGE = ImageManager.getImage(OteDefineImage.COMMIT);
+
+ private static final String MESSAGE_TITLE = "Select a report";
+ private static final String TITLE_BAR_TEXT = "OSEE Test Run Reports";
+ private static final String MESSAGE = "The preview window displays an example of the selected report.";
+ private static final String REPORT_SELECTION_TITLE = "Select a Report";
+ private static final String PREVIEW_TITLE = "Preview";
+ private static final String FORMAT_TITLE = "Select a Format";
+ private static final String REPORT_DESCRIPTION = "Report Description";
+ private static final String PREVIEW_DESCRIPTION = "Enter Preview Size";
+
+ private static final String REPORT_STORE_ID = ReportsDialog.class.getName() + ".reportId";
+ private static final String FORMAT_STORE_ID = ReportsDialog.class.getName() + ".formatId";
+ private static final String PREVIEW_SIZE_STORE_ID = ReportsDialog.class.getName() + ".previewSize";
+
+ private static final int DEFAULT_PREVIEW_SIZE = 5;
+
+ private PreviewPanel previewPanel;
+ private org.eclipse.osee.ote.ui.define.panels.ListSelectionPanel listSelectionPanel;
+ private SelectionChangedListener selectionChangedListener;
+ private Text descriptionArea;
+ private Text previewSizeArea;
+ private String selectedReportId;
+ private OutputFormat selectedReportFormat;
+ private final List<IFile> filesToDelete;
+ private Map<OutputFormat, Button> formatButtons;
+
+ public ReportsDialog(Shell parent) {
+ super(parent);
+ this.filesToDelete = new ArrayList<IFile>();
+ setShellStyle(SWT.SHELL_TRIM);
+ }
+
+ @Override
+ protected Control createButtonBar(Composite parent) {
+ Label separator = new Label(parent, SWT.HORIZONTAL | SWT.SEPARATOR);
+ separator.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
+ return super.createButtonBar(parent);
+ }
+
+ /*
+ * @see Dialog#createDialogArea(Composite)
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite content = (Composite) super.createDialogArea(parent);
+
+ Composite composite = new Composite(content, SWT.NONE);
+ composite.setLayout(new GridLayout());
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ composite.setFont(parent.getFont());
+
+ SashForm sash = new SashForm(composite, SWT.HORIZONTAL);
+ sash.setLayout(new GridLayout());
+ sash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ sash.setFont(parent.getFont());
+
+ createReportSelectionArea(sash);
+
+ Composite panel = new Composite(sash, SWT.NONE);
+ GridLayout gL1 = new GridLayout();
+ gL1.marginHeight = 0;
+ gL1.marginWidth = 0;
+ panel.setLayout(gL1);
+ panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ createFormatAndDescriptionArea(panel);
+ createPreviewArea(panel);
+ sash.setWeights(new int[] {1, 2});
+
+ setTitle(MESSAGE_TITLE);
+ setTitleImage(MESSAGE_IMAGE);
+ setMessage(MESSAGE);
+ getShell().setText(TITLE_BAR_TEXT);
+ getShell().setImage(TITLE_BAR_IMAGE);
+ attachListeners();
+ restoreDialog();
+ return sash;
+ }
+
+ private void restoreDialog() {
+ IDialogSettings settings = OteUiDefinePlugin.getInstance().getDialogSettings();
+ if (settings != null) {
+ String reportSelected = settings.get(REPORT_STORE_ID);
+ String format = settings.get(FORMAT_STORE_ID);
+
+ int value = 0;
+ try {
+ value = settings.getInt(PREVIEW_SIZE_STORE_ID);
+ } catch (Exception ex) {
+ value = DEFAULT_PREVIEW_SIZE;
+ }
+ clamp(previewSizeArea, value);
+
+ OutputFormat outputFormat = OutputFormat.HTML;
+ int index = 0;
+ if (Strings.isValid(reportSelected) && Strings.isValid(format)) {
+ Pair<String, String> pair = ExtensionDefinedReports.getInstance().getIdAndName(reportSelected);
+ index = listSelectionPanel.indexOf(pair);
+ outputFormat = OutputFormat.fromString(format);
+ }
+ if (index > -1) {
+ listSelectionPanel.setSelection(index);
+ }
+ setReportFormat(outputFormat);
+ for (OutputFormat key : formatButtons.keySet()) {
+ Button button = formatButtons.get(key);
+ button.setSelection(key.equals(outputFormat));
+ }
+ }
+ }
+
+ private void saveDialog() {
+ IDialogSettings settings = OteUiDefinePlugin.getInstance().getDialogSettings();
+ if (settings != null) {
+ String reportSelected = getReportSelected();
+ String format = getReportFormat();
+ int previewSize = getPreviewSize();
+ settings.put(REPORT_STORE_ID, reportSelected);
+ settings.put(FORMAT_STORE_ID, format);
+ settings.put(PREVIEW_SIZE_STORE_ID, previewSize);
+ }
+ }
+
+ @Override
+ protected void okPressed() {
+ saveDialog();
+ cleanUp(filesToDelete);
+ super.okPressed();
+ }
+
+ private void createReportSelectionArea(Composite parent) {
+ Group composite = new Group(parent, SWT.NONE);
+ composite.setLayout(new GridLayout());
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ composite.setFont(parent.getFont());
+ composite.setText(REPORT_SELECTION_TITLE);
+
+ listSelectionPanel = new ListSelectionPanel(composite, SWT.NONE, 300, 300, new ListLabelProvider());
+ listSelectionPanel.setSorter(new ViewerSorter() {
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public int compare(Viewer viewer, Object o1, Object o2) {
+ Pair<String, String> pair1 = (Pair<String, String>) o1;
+ Pair<String, String> pair2 = (Pair<String, String>) o2;
+ return getComparator().compare(pair1.getSecond(), pair2.getSecond());
+ }
+
+ });
+ Pair<String, String>[] reportNames = ExtensionDefinedReports.getInstance().getIdsAndNames();
+ listSelectionPanel.setInput(reportNames);
+ listSelectionPanel.setSelection(0);
+ }
+
+ private void createFormatAndDescriptionArea(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout gL = new GridLayout(2, false);
+ gL.marginHeight = 0;
+ gL.marginWidth = 0;
+ composite.setLayout(gL);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ createFormatArea(composite);
+
+ Composite panel = new Composite(composite, SWT.NONE);
+ GridLayout gL1 = new GridLayout();
+ gL1.marginHeight = 0;
+ gL1.marginWidth = 0;
+ panel.setLayout(gL1);
+ panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+
+ createDescriptionArea(panel);
+ createPreviewSizeArea(panel);
+ }
+
+ private void createPreviewSizeArea(Composite parent) {
+ Group group = new Group(parent, SWT.NONE);
+ group.setLayout(new GridLayout(2, false));
+ group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ group.setFont(parent.getFont());
+ group.setText(PREVIEW_DESCRIPTION);
+
+ previewSizeArea = new Text(group, SWT.SINGLE | SWT.BORDER);
+ previewSizeArea.setTextLimit(2);
+ GridData gd = new GridData(SWT.RIGHT, SWT.FILL, false, false);
+ gd.heightHint = convertHeightInCharsToPixels(1);
+ gd.widthHint = convertWidthInCharsToPixels(4);
+ previewSizeArea.setLayoutData(gd);
+ new Widgets.IntegerTextEntryHandler(previewSizeArea, false, 2) {
+ @Override
+ public void applyValue(long value) {
+ clamp(previewSizeArea, value);
+ }
+ };
+
+ Label label = new Label(group, SWT.NONE);
+ label.setText("[ 0-10 ]");
+ label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ }
+
+ private void clamp(Text text, long value) {
+ if (value < 0) {
+ previewSizeArea.setText(Integer.toString(0));
+ }
+ if (value > 10) {
+ previewSizeArea.setText(Integer.toString(10));
+ }
+ }
+
+ private void createDescriptionArea(Composite parent) {
+ Group group = new Group(parent, SWT.NONE);
+ group.setLayout(new GridLayout());
+ group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ group.setFont(parent.getFont());
+ group.setText(REPORT_DESCRIPTION);
+
+ descriptionArea = new Text(group, SWT.WRAP | SWT.MULTI);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gd.heightHint = 100;
+ gd.widthHint = 100;
+ descriptionArea.setLayoutData(gd);
+ descriptionArea.setEditable(false);
+ }
+
+ private void createFormatArea(Composite parent) {
+ Group group = new Group(parent, SWT.NONE);
+ group.setLayout(new GridLayout());
+ group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
+ group.setFont(parent.getFont());
+ group.setText(FORMAT_TITLE);
+
+ this.formatButtons = new HashMap<OutputFormat, Button>();
+ for (OutputFormat format : OutputFormat.values()) {
+ Button button = new Button(group, SWT.RADIO);
+ button.setText(format.name());
+ button.setData(format);
+ if (format.equals(OutputFormat.HTML)) {
+ button.setSelection(true);
+ }
+ button.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Button button = (Button) e.getSource();
+ if (button.getSelection() != false) {
+ setReportFormat((OutputFormat) button.getData());
+ }
+ }
+ });
+ formatButtons.put(format, button);
+ }
+ }
+
+ private void createPreviewArea(Composite parent) {
+ Group group = new Group(parent, SWT.NONE);
+ group.setLayout(new GridLayout());
+ group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ group.setFont(parent.getFont());
+ group.setText(PREVIEW_TITLE);
+ previewPanel = new PreviewPanel(group, SWT.NONE);
+ }
+
+ private void attachListeners() {
+ listSelectionPanel.addDoubleClickListener(new IDoubleClickListener() {
+ @SuppressWarnings("unchecked")
+ public void doubleClick(DoubleClickEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ if (selection != null) {
+ Pair<String, String> item = (Pair<String, String>) selection.getFirstElement();
+ if (item != null) {
+ selectedReportId = item.getFirst();
+ }
+ }
+ okPressed();
+ }
+ });
+
+ selectionChangedListener = new SelectionChangedListener();
+ listSelectionPanel.addSelectionChangedListener(selectionChangedListener);
+ }
+
+ public String getReportSelected() {
+ return selectedReportId;
+ }
+
+ public String getReportFormat() {
+ return selectedReportFormat.name();
+ }
+
+ private void setReportFormat(OutputFormat reportFormat) {
+ this.selectedReportFormat = reportFormat;
+ selectionChangedListener.selectionChanged(null);
+ }
+
+ private PanelEnum asPanelEnum(OutputFormat format) {
+ PanelEnum toReturn = PanelEnum.DEFAULT;
+ switch (format) {
+ case HTML:
+ case PDF:
+ case EXCEL:
+ case RTF:
+ toReturn = PanelEnum.BROWSER;
+ break;
+ default:
+ toReturn = PanelEnum.DEFAULT;
+ break;
+ }
+ return toReturn;
+ }
+
+ private void updatePanel(final PanelEnum panelId, final URI uri, final String description, final List<IFile> oldIFiles) {
+ Displays.ensureInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ previewPanel.updatePreview(panelId, uri);
+ previewPanel.setDisplay(panelId);
+ descriptionArea.setText(description);
+ }
+ });
+ cleanUp(oldIFiles);
+ }
+
+ private int getPreviewSize() {
+ int toReturn = DEFAULT_PREVIEW_SIZE;
+ String value = previewSizeArea.getText();
+ try {
+ toReturn = Integer.parseInt(value);
+ } catch (Exception ex) {
+ toReturn = DEFAULT_PREVIEW_SIZE;
+ updatePreviewSizeValue(toReturn);
+ }
+ return toReturn;
+ }
+
+ private void updatePreviewSizeValue(final int value) {
+ Displays.ensureInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ previewSizeArea.setText(Integer.toString(value));
+ }
+ });
+ }
+
+ private void generatePreview(final OutputFormat outputFormat, final String reportId, final ITestRunReport report) throws URISyntaxException, OseeStateException {
+ String urlRequest = HttpReportRequest.getUrl(reportId, outputFormat.name(), "local", getPreviewSize());
+ String fileName = OutputFactory.getOutputFilename(outputFormat, reportId);
+ switch (outputFormat) {
+ case HTML:
+ updatePanel(asPanelEnum(outputFormat), new URI(urlRequest), report.getDescription(), filesToDelete);
+ break;
+ default:
+ remoteFileToLocal(outputFormat, urlRequest, fileName, report);
+ break;
+ }
+ }
+
+ private void remoteFileToLocal(final OutputFormat outputFormat, final String urlRequest, final String fileName, final ITestRunReport report) {
+ RemoteResourceRequestJob requestJob = new RemoteResourceRequestJob(urlRequest, fileName);
+ requestJob.addJobChangeListener(new PreviewUpdateJobChangeListener(report, outputFormat));
+ requestJob.getDownloadedFile();
+ requestJob.schedule();
+ }
+
+ private final class SelectionChangedListener implements ISelectionChangedListener {
+ @SuppressWarnings("unchecked")
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = listSelectionPanel.getSelection();
+ if (selection != null) {
+ Pair<String, String> item = (Pair<String, String>) selection.getFirstElement();
+ if (item != null) {
+ ITestRunReport report = ExtensionDefinedReports.getInstance().getReportGenerator(item.getFirst());
+ if (report != null) {
+ selectedReportId = item.getFirst();
+ try {
+ generatePreview(selectedReportFormat, selectedReportId, report);
+ } catch (Exception ex) {
+ OseeLog.log(OteUiDefinePlugin.class, Level.SEVERE, ex);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private final class ListLabelProvider extends LabelProvider {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Image getImage(Object element) {
+ Image toReturn = null;
+ if (element instanceof Pair) {
+ toReturn = ExtensionDefinedReports.getInstance().getImage(((Pair<String, String>) element).getFirst());
+ }
+ return toReturn;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public String getText(Object element) {
+ if (element instanceof Pair) {
+ return ((Pair<String, String>) element).getSecond();
+ }
+ return super.getText(element);
+ }
+ }
+
+ private final class PreviewUpdateJobChangeListener extends JobChangeAdapter {
+ private final ITestRunReport report;
+ private final OutputFormat format;
+
+ private PreviewUpdateJobChangeListener(ITestRunReport report, OutputFormat format) {
+ this.report = report;
+ this.format = format;
+ }
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ IStatus status = event.getResult();
+ if (status.equals(Status.OK_STATUS) || status.getCode() == Status.OK) {
+ IFile iFile = ((RemoteResourceRequestJob) event.getJob()).getDownloadedFile();
+ if (iFile != null) {
+ updatePanel(asPanelEnum(format), iFile.getLocationURI(), report.getDescription(), filesToDelete);
+ filesToDelete.add(iFile);
+ }
+ }
+ }
+ }
+
+ private void cleanUp(final List<IFile> iFiles) {
+ Displays.ensureInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ for (IFile iFile : iFiles) {
+ if (iFile != null && iFile.exists()) {
+ try {
+ iFile.delete(true, new NullProgressMonitor());
+ filesToDelete.remove(iFile);
+ } catch (CoreException ex) {
+ // Do Nothing
+ }
+ }
+ }
+ }
+ });
+ }
}
diff --git a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/importer/ImportOutfileUIOperation.java b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/importer/ImportOutfileUIOperation.java index be5399e3bdc..bd7eda8597b 100644 --- a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/importer/ImportOutfileUIOperation.java +++ b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/importer/ImportOutfileUIOperation.java @@ -8,8 +8,8 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.ote.ui.define.importer;
-
+package org.eclipse.osee.ote.ui.define.importer; + import java.net.URI; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -18,108 +18,108 @@ import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.osee.framework.core.model.Branch; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; +import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.osee.ote.define.jobs.FindCommitableJob; import org.eclipse.osee.ote.define.jobs.OutfileToArtifactJob; import org.eclipse.osee.ote.ui.define.jobs.CommitTestRunJob; import org.eclipse.osee.ote.ui.define.jobs.ReportErrorsJob; import org.eclipse.osee.ote.ui.define.utilities.CommitConfiguration; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; -
-/**
- * @author Roberto E. Escobar
- */
-public class ImportOutfileUIOperation {
-
- private URI[] fileSystemObjects;
- private Branch selectedBranch;
-
- public ImportOutfileUIOperation(Branch selectedBranch, URI... fileSystemObjects) {
- this.fileSystemObjects = fileSystemObjects;
- this.selectedBranch = selectedBranch;
- }
-
- public boolean execute() {
- boolean toReturn = true;
- if (fileSystemObjects.length > 0) {
- launchImportJob();
- } else {
- toReturn = false;
- Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
- MessageDialog.openInformation(shell, "Information", "There were no resources currently selected for import.");
- }
- return toReturn;
- }
-
- private void launchImportJob() {
- OutfileToArtifactJob convertJob = new OutfileToArtifactJob(selectedBranch, fileSystemObjects);
- convertJob.addJobChangeListener(new JobChangeAdapter() {
-
- @Override
- public void done(IJobChangeEvent event) {
- if (wasJobSuccessful(event)) {
- OutfileToArtifactJob job = (OutfileToArtifactJob) event.getJob();
-
- URI[] itemsWithError = job.getUnparseableFiles();
- Artifact[] artifacts = job.getResults();
- // Report Parse Errors
- if (itemsWithError.length > 0) {
- reportFilesWithErrors(itemsWithError, artifacts);
- } else {
- launchFindCommitableJob(artifacts);
- }
- }
- }
- });
- convertJob.schedule();
- }
-
- private void launchCommitJob(final FindCommitableJob job) {
- Display.getDefault().asyncExec(new Runnable() {
-
- public void run() {
- CommitTestRunJob newJob =
- new CommitTestRunJob(job.getAll(), job.getCommitAllowed(), job.getCommitNotAllowed(),
- CommitConfiguration.isCommitOverrideAllowed());
- newJob.schedule();
- }
- });
- }
-
- private void launchFindCommitableJob(final Artifact[] artifacts) {
- // Find Commit Allowed
- FindCommitableJob commitableJob = new FindCommitableJob(artifacts);
- commitableJob.addJobChangeListener(new JobChangeAdapter() {
-
- @Override
- public void done(IJobChangeEvent event) {
- if (wasJobSuccessful(event)) {
- FindCommitableJob job = (FindCommitableJob) event.getJob();
- launchCommitJob(job);
- }
- }
- });
- commitableJob.schedule();
- }
-
- private void reportFilesWithErrors(final Object[] items, final Artifact[] artifacts) {
- String title = "Outfile Import Error";
- String message = "The following file(s) had errors during the parsing operation: ";
-
- JobChangeAdapter listener = new JobChangeAdapter() {
-
- @Override
- public void done(IJobChangeEvent event) {
- launchFindCommitableJob(artifacts);
- }
- };
-
- ReportErrorsJob.openError(title, message, listener, items);
- }
-
- private boolean wasJobSuccessful(IJobChangeEvent event) {
- IStatus status = event.getResult();
- return status.equals(Status.OK_STATUS) || status.equals(Status.OK);
- }
-}
+ +/** + * @author Roberto E. Escobar + */ +public class ImportOutfileUIOperation { + + private final URI[] fileSystemObjects; + private final Branch selectedBranch; + + public ImportOutfileUIOperation(Branch selectedBranch, URI... fileSystemObjects) { + this.fileSystemObjects = fileSystemObjects; + this.selectedBranch = selectedBranch; + } + + public boolean execute() { + boolean toReturn = true; + if (fileSystemObjects.length > 0) { + launchImportJob(); + } else { + toReturn = false; + Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell(); + MessageDialog.openInformation(shell, "Information", "There were no resources currently selected for import."); + } + return toReturn; + } + + private void launchImportJob() { + OutfileToArtifactJob convertJob = new OutfileToArtifactJob(selectedBranch, fileSystemObjects); + convertJob.addJobChangeListener(new JobChangeAdapter() { + + @Override + public void done(IJobChangeEvent event) { + if (wasJobSuccessful(event)) { + OutfileToArtifactJob job = (OutfileToArtifactJob) event.getJob(); + + URI[] itemsWithError = job.getUnparseableFiles(); + Artifact[] artifacts = job.getResults(); + // Report Parse Errors + if (itemsWithError.length > 0) { + reportFilesWithErrors(itemsWithError, artifacts); + } else { + launchFindCommitableJob(artifacts); + } + } + } + }); + convertJob.schedule(); + } + + private void launchCommitJob(final FindCommitableJob job) { + Displays.ensureInDisplayThread(new Runnable() { + @Override + public void run() { + CommitTestRunJob newJob = + new CommitTestRunJob(job.getAll(), job.getCommitAllowed(), job.getCommitNotAllowed(), + CommitConfiguration.isCommitOverrideAllowed()); + newJob.schedule(); + } + }); + } + + private void launchFindCommitableJob(final Artifact[] artifacts) { + // Find Commit Allowed + FindCommitableJob commitableJob = new FindCommitableJob(artifacts); + commitableJob.addJobChangeListener(new JobChangeAdapter() { + + @Override + public void done(IJobChangeEvent event) { + if (wasJobSuccessful(event)) { + FindCommitableJob job = (FindCommitableJob) event.getJob(); + launchCommitJob(job); + } + } + }); + commitableJob.schedule(); + } + + private void reportFilesWithErrors(final Object[] items, final Artifact[] artifacts) { + String title = "Outfile Import Error"; + String message = "The following file(s) had errors during the parsing operation: "; + + JobChangeAdapter listener = new JobChangeAdapter() { + + @Override + public void done(IJobChangeEvent event) { + launchFindCommitableJob(artifacts); + } + }; + + ReportErrorsJob.openError(title, message, listener, items); + } + + private boolean wasJobSuccessful(IJobChangeEvent event) { + IStatus status = event.getResult(); + return status.equals(Status.OK_STATUS) || status.equals(Status.OK); + } +} diff --git a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/jobs/ReportErrorsJob.java b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/jobs/ReportErrorsJob.java index cdb3a364455..0ad10beee3a 100644 --- a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/jobs/ReportErrorsJob.java +++ b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/jobs/ReportErrorsJob.java @@ -8,8 +8,8 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.ote.ui.define.jobs;
-
+package org.eclipse.osee.ote.ui.define.jobs; + import java.util.Arrays; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -17,85 +17,87 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.IJobChangeListener; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.progress.UIJob; -
-/**
- * @author Roberto E. Escobar
- */
-public class ReportErrorsJob extends UIJob {
-
- private Object[] objectsWithErrors;
- private String message;
-
- private ReportErrorsJob(String title, String message, Object... objectsWithErrors) {
- super(title);
- setUser(false);
- setPriority(LONG);
- this.objectsWithErrors = objectsWithErrors;
- this.message = message;
- }
-
- public IStatus runInUIThread(IProgressMonitor monitor) {
- final String errorMessage = Arrays.deepToString(objectsWithErrors).replaceAll(",", ",\n");
- Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
- ResourceErrorDialog dialog = new ResourceErrorDialog(shell, getName(), message, errorMessage);
- dialog.open();
- return Status.OK_STATUS;
- }
-
- public static void openError(final String title, final String message, final Object... objectsWithErrors) {
- openError(title, message, null, objectsWithErrors);
- }
-
- public static void openError(final String title, final String message, final IJobChangeListener listener, final Object... objectsWithErrors) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- ReportErrorsJob errorDialog = new ReportErrorsJob(title, message, objectsWithErrors);
- if (listener != null) {
- errorDialog.addJobChangeListener(listener);
- }
- errorDialog.schedule();
- }
- });
- }
- private final class ResourceErrorDialog extends MessageDialog {
-
- private String errorMessage;
-
- public ResourceErrorDialog(Shell parentShell, String dialogTitle, String dialogMessage, String errorMessage) {
- super(parentShell, dialogTitle, PlatformUI.getWorkbench().getSharedImages().getImage(
- ISharedImages.IMG_OBJS_ERROR_TSK), dialogMessage, MessageDialog.ERROR,
- new String[] {IDialogConstants.OK_LABEL}, 0);
- this.errorMessage = errorMessage;
- }
-
- @Override
- protected Control createCustomArea(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- composite.setLayout(new GridLayout());
-
- Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
- data.heightHint = 300;
- data.widthHint = 300;
- data.minimumWidth = 300;
- data.minimumHeight = 300;
- text.setLayoutData(data);
- text.setEditable(false);
- text.setText(errorMessage);
- text.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_WHITE));
- return composite;
- }
- }
-}
+ +/** + * @author Roberto E. Escobar + */ +public class ReportErrorsJob extends UIJob { + + private final Object[] objectsWithErrors; + private final String message; + + private ReportErrorsJob(String title, String message, Object... objectsWithErrors) { + super(title); + setUser(false); + setPriority(LONG); + this.objectsWithErrors = objectsWithErrors; + this.message = message; + } + + @Override + public IStatus runInUIThread(IProgressMonitor monitor) { + final String errorMessage = Arrays.deepToString(objectsWithErrors).replaceAll(",", ",\n"); + Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell(); + ResourceErrorDialog dialog = new ResourceErrorDialog(shell, getName(), message, errorMessage); + dialog.open(); + return Status.OK_STATUS; + } + + public static void openError(final String title, final String message, final Object... objectsWithErrors) { + openError(title, message, null, objectsWithErrors); + } + + public static void openError(final String title, final String message, final IJobChangeListener listener, final Object... objectsWithErrors) { + Displays.ensureInDisplayThread(new Runnable() { + @Override + public void run() { + ReportErrorsJob errorDialog = new ReportErrorsJob(title, message, objectsWithErrors); + if (listener != null) { + errorDialog.addJobChangeListener(listener); + } + errorDialog.schedule(); + } + }); + } + private final class ResourceErrorDialog extends MessageDialog { + + private final String errorMessage; + + public ResourceErrorDialog(Shell parentShell, String dialogTitle, String dialogMessage, String errorMessage) { + super(parentShell, dialogTitle, PlatformUI.getWorkbench().getSharedImages().getImage( + ISharedImages.IMG_OBJS_ERROR_TSK), dialogMessage, MessageDialog.ERROR, + new String[] {IDialogConstants.OK_LABEL}, 0); + this.errorMessage = errorMessage; + } + + @Override + protected Control createCustomArea(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + composite.setLayout(new GridLayout()); + + Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.heightHint = 300; + data.widthHint = 300; + data.minimumWidth = 300; + data.minimumHeight = 300; + text.setLayoutData(data); + text.setEditable(false); + text.setText(errorMessage); + text.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_WHITE)); + return composite; + } + } +} diff --git a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/panels/GrayableBranchSelectionComposite.java b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/panels/GrayableBranchSelectionComposite.java index 38245a9193c..de94b1893ab 100644 --- a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/panels/GrayableBranchSelectionComposite.java +++ b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/panels/GrayableBranchSelectionComposite.java @@ -17,8 +17,8 @@ import org.eclipse.osee.framework.skynet.core.event.IAccessControlEventListener; import org.eclipse.osee.framework.skynet.core.event.OseeEventManager; import org.eclipse.osee.framework.skynet.core.event.Sender; import org.eclipse.osee.framework.skynet.core.event2.AccessControlEvent; -import org.eclipse.osee.framework.ui.plugin.util.Displays; import org.eclipse.osee.framework.ui.skynet.panels.BranchSelectSimpleComposite; +import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StackLayout; import org.eclipse.swt.events.SelectionAdapter; @@ -28,7 +28,6 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.ui.ISharedImages; @@ -39,180 +38,182 @@ import org.eclipse.ui.PlatformUI; */ public class GrayableBranchSelectionComposite extends Composite implements IAccessControlEventListener { - private static final String GROUP_TEXT = "Upload results into OSEE"; - private static final String CHECK_BUTTON_TEXT = "Enable upload"; - private static final String CHECK_BUTTON_TOOL_TIP = - "Select to store outfiles as Test Run Artifacts.\n" + "NOTE: User must be authenticated to create Artifacts."; - private static final String AUTHENTICATION_WARNING_MESSAGE = - "Authentication failure - Outfile upload not allowed. Double-Click on the lock icon at the bottom of the screen to authenticate."; - private static final String FEATURE_DISABLED = "Feature disabled."; - - private BranchSelectSimpleComposite branchSelectComposite; - private Button branchSelectEnabled; - private Composite statusComposite; - private Composite selectableComposite; - private Label statusLabel; - private StackLayout stackedLayout; - private Group group; - private boolean featureEnabled; - - public GrayableBranchSelectionComposite(Composite parent, int style) { - super(parent, style); - createControl(this); - } - - @Override - public void handleAccessControlArtifactsEvent(Sender sender, AccessControlEvent accessControlEvent) { - if (accessControlEvent.getEventType() == AccessControlEventType.UserAuthenticated) { - handleUserAuthenticated(); - } - } - - private void createControl(Composite parent) { - GridLayout gL = new GridLayout(); - gL.marginWidth = 0; - gL.marginHeight = 0; - parent.setLayout(gL); - parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - - group = new Group(parent, SWT.NONE); - group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - stackedLayout = new StackLayout(); - group.setLayout(stackedLayout); - group.setText(GROUP_TEXT); - - createStatusBar(group); - createSelectableArea(group); - handleBranchSelectEnabled(false); - OseeEventManager.addListener(this); - } - - private void createSelectableArea(Composite parent) { - selectableComposite = new Composite(parent, SWT.NONE); - selectableComposite.setLayout(new GridLayout()); - selectableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - - branchSelectEnabled = new Button(selectableComposite, SWT.CHECK); - branchSelectEnabled.setText(CHECK_BUTTON_TEXT); - branchSelectEnabled.setToolTipText(CHECK_BUTTON_TOOL_TIP); - - branchSelectEnabled.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - handleBranchSelectEnabled(branchSelectEnabled.getSelection()); - } - }); - this.branchSelectComposite = - BranchSelectSimpleComposite.createWorkingBranchSelectComposite(selectableComposite, SWT.NONE); - } - - private void createStatusBar(Composite parent) { - statusComposite = new Composite(parent, SWT.BORDER); - statusComposite.setLayout(new GridLayout(2, false)); - statusComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false)); - statusComposite.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - statusComposite.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); - - Label imageLabel = new Label(statusComposite, SWT.NONE); - imageLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); - imageLabel.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK)); - imageLabel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - imageLabel.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); - - statusLabel = new Label(statusComposite, SWT.NONE); - statusLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - statusLabel.setText(""); - statusLabel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - statusLabel.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED)); - } - - private void handleBranchSelectEnabled(boolean isSelected) { - setSelectable(true); - if (ClientSessionManager.isSessionValid() != true) { - statusLabel.setText(AUTHENTICATION_WARNING_MESSAGE); - setSelectable(false); - isSelected = false; - } - branchSelectEnabled.setSelection(isSelected); - branchSelectComposite.setEnabled(isSelected); - for (Control control : branchSelectComposite.getChildren()) { - control.setEnabled(isSelected); - } - } - - public Branch getSelectedBranch() { - return branchSelectComposite.getSelectedBranch(); - } - - public boolean isBranchSelectEnabled() { - return branchSelectEnabled.getSelection(); - } - - public void setFeatureEnabled(final boolean isEnabled) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - featureEnabled = isEnabled; - handleBranchSelectEnabled(false); - statusLabel.setText(featureEnabled != true ? FEATURE_DISABLED : ""); - setEnabled(featureEnabled); - setSelectable(featureEnabled); - } - }); - } - - private boolean isFeatureEnabled() { - return featureEnabled; - } - - @Override - public void setEnabled(boolean enabled) { - super.setEnabled(enabled); - for (Control child : group.getChildren()) { - child.setEnabled(enabled); - } - branchSelectEnabled.setEnabled(enabled); - } - - public String[] getBranchIds() { - return branchSelectComposite.getBranchIds(); - } - - public void restoreWidgetValues(boolean saveAsArtifact, String[] branchIds, String lastSelected) { - branchSelectEnabled.setSelection(saveAsArtifact && ClientSessionManager.isSessionValid()); - branchSelectComposite.restoreWidgetValues(branchIds, lastSelected); - } - - private void setSelectable(final boolean isSelectable) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (isSelectable != false) { - stackedLayout.topControl = selectableComposite; - } else { - stackedLayout.topControl = statusComposite; - } - group.layout(); - } - }); - } - - @Override - public void dispose() { - OseeEventManager.removeListener(this); - super.dispose(); - } - - private void handleUserAuthenticated() { - Displays.ensureInDisplayThread(new Runnable() { - @Override - public void run() { - if (branchSelectEnabled != null && branchSelectEnabled.isDisposed() != true && isFeatureEnabled() != false) { - handleBranchSelectEnabled(branchSelectEnabled.getSelection()); - } - } - }); - } - - public boolean runOnEventInDisplayThread() { - return true; - } + private static final String GROUP_TEXT = "Upload results into OSEE"; + private static final String CHECK_BUTTON_TEXT = "Enable upload"; + private static final String CHECK_BUTTON_TOOL_TIP = + "Select to store outfiles as Test Run Artifacts.\n" + "NOTE: User must be authenticated to create Artifacts."; + private static final String AUTHENTICATION_WARNING_MESSAGE = + "Authentication failure - Outfile upload not allowed. Double-Click on the lock icon at the bottom of the screen to authenticate."; + private static final String FEATURE_DISABLED = "Feature disabled."; + + private BranchSelectSimpleComposite branchSelectComposite; + private Button branchSelectEnabled; + private Composite statusComposite; + private Composite selectableComposite; + private Label statusLabel; + private StackLayout stackedLayout; + private Group group; + private boolean featureEnabled; + + public GrayableBranchSelectionComposite(Composite parent, int style) { + super(parent, style); + createControl(this); + } + + @Override + public void handleAccessControlArtifactsEvent(Sender sender, AccessControlEvent accessControlEvent) { + if (accessControlEvent.getEventType() == AccessControlEventType.UserAuthenticated) { + handleUserAuthenticated(); + } + } + + private void createControl(Composite parent) { + GridLayout gL = new GridLayout(); + gL.marginWidth = 0; + gL.marginHeight = 0; + parent.setLayout(gL); + parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + group = new Group(parent, SWT.NONE); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + stackedLayout = new StackLayout(); + group.setLayout(stackedLayout); + group.setText(GROUP_TEXT); + + createStatusBar(group); + createSelectableArea(group); + handleBranchSelectEnabled(false); + OseeEventManager.addListener(this); + } + + private void createSelectableArea(Composite parent) { + selectableComposite = new Composite(parent, SWT.NONE); + selectableComposite.setLayout(new GridLayout()); + selectableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + branchSelectEnabled = new Button(selectableComposite, SWT.CHECK); + branchSelectEnabled.setText(CHECK_BUTTON_TEXT); + branchSelectEnabled.setToolTipText(CHECK_BUTTON_TOOL_TIP); + + branchSelectEnabled.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + handleBranchSelectEnabled(branchSelectEnabled.getSelection()); + } + }); + this.branchSelectComposite = + BranchSelectSimpleComposite.createWorkingBranchSelectComposite(selectableComposite, SWT.NONE); + } + + private void createStatusBar(Composite parent) { + statusComposite = new Composite(parent, SWT.BORDER); + statusComposite.setLayout(new GridLayout(2, false)); + statusComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false)); + statusComposite.setBackground(Displays.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + statusComposite.setForeground(Displays.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); + + Label imageLabel = new Label(statusComposite, SWT.NONE); + imageLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); + imageLabel.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK)); + imageLabel.setBackground(Displays.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + imageLabel.setForeground(Displays.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); + + statusLabel = new Label(statusComposite, SWT.NONE); + statusLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + statusLabel.setText(""); + statusLabel.setBackground(Displays.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + statusLabel.setForeground(Displays.getSystemColor(SWT.COLOR_RED)); + } + + private void handleBranchSelectEnabled(boolean isSelected) { + setSelectable(true); + if (ClientSessionManager.isSessionValid() != true) { + statusLabel.setText(AUTHENTICATION_WARNING_MESSAGE); + setSelectable(false); + isSelected = false; + } + branchSelectEnabled.setSelection(isSelected); + branchSelectComposite.setEnabled(isSelected); + for (Control control : branchSelectComposite.getChildren()) { + control.setEnabled(isSelected); + } + } + + public Branch getSelectedBranch() { + return branchSelectComposite.getSelectedBranch(); + } + + public boolean isBranchSelectEnabled() { + return branchSelectEnabled.getSelection(); + } + + public void setFeatureEnabled(final boolean isEnabled) { + Displays.ensureInDisplayThread(new Runnable() { + @Override + public void run() { + featureEnabled = isEnabled; + handleBranchSelectEnabled(false); + statusLabel.setText(featureEnabled != true ? FEATURE_DISABLED : ""); + setEnabled(featureEnabled); + setSelectable(featureEnabled); + } + }); + } + + private boolean isFeatureEnabled() { + return featureEnabled; + } + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + for (Control child : group.getChildren()) { + child.setEnabled(enabled); + } + branchSelectEnabled.setEnabled(enabled); + } + + public String[] getBranchIds() { + return branchSelectComposite.getBranchIds(); + } + + public void restoreWidgetValues(boolean saveAsArtifact, String[] branchIds, String lastSelected) { + branchSelectEnabled.setSelection(saveAsArtifact && ClientSessionManager.isSessionValid()); + branchSelectComposite.restoreWidgetValues(branchIds, lastSelected); + } + + private void setSelectable(final boolean isSelectable) { + Displays.ensureInDisplayThread(new Runnable() { + @Override + public void run() { + if (isSelectable != false) { + stackedLayout.topControl = selectableComposite; + } else { + stackedLayout.topControl = statusComposite; + } + group.layout(); + } + }); + } + + @Override + public void dispose() { + OseeEventManager.removeListener(this); + super.dispose(); + } + + private void handleUserAuthenticated() { + Displays.ensureInDisplayThread(new Runnable() { + @Override + public void run() { + if (branchSelectEnabled != null && branchSelectEnabled.isDisposed() != true && isFeatureEnabled() != false) { + handleBranchSelectEnabled(branchSelectEnabled.getSelection()); + } + } + }); + } + + public boolean runOnEventInDisplayThread() { + return true; + } } diff --git a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/panels/PreviewPanel.java b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/panels/PreviewPanel.java index 501dfea4495..ea7780ba909 100644 --- a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/panels/PreviewPanel.java +++ b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/panels/PreviewPanel.java @@ -8,11 +8,12 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.ote.ui.define.panels;
-
+package org.eclipse.osee.ote.ui.define.panels; + import java.net.URI; import java.util.logging.Level; import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.osee.ote.ui.define.OteUiDefinePlugin; import org.eclipse.swt.SWT; import org.eclipse.swt.browser.Browser; @@ -25,89 +26,90 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.ui.PlatformUI; -
-/**
- * @author Roberto E. Escobar
- */
-public class PreviewPanel extends Composite {
- private static final String PREVIEW_DEFAULT_TITLE = "Preview Not Available";
-
- public enum PanelEnum {
- DEFAULT, BROWSER;
- }
-
- private Composite stackedComposite;
- private StackLayout stackLayout;
- private Composite defaultComposite;
- private Browser browser;
-
- public PreviewPanel(Composite parent, int style) {
- super(parent, style);
- GridLayout layout = new GridLayout();
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- this.setLayout(layout);
- this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- createControl(this);
- }
-
- private void createControl(Composite parent) {
- stackedComposite = new Composite(parent, SWT.BORDER);
- stackLayout = new StackLayout();
- stackLayout.marginWidth = 0;
- stackLayout.marginHeight = 0;
- stackedComposite.setLayout(stackLayout);
- stackedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- createBrowserArea(stackedComposite);
- createPreviewNotAllowed(stackedComposite);
- }
-
- private void createBrowserArea(Composite parent) {
- browser = new Browser(parent, SWT.EMBEDDED | SWT.BORDER);
- browser.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
- browser.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GREEN));
- }
-
- private void createPreviewNotAllowed(Composite parent) {
- defaultComposite = new Composite(parent, SWT.BORDER);
- defaultComposite.setLayout(new GridLayout());
- defaultComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- defaultComposite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
-
- Label label = new Label(defaultComposite, SWT.NONE);
- Font font = new Font(PlatformUI.getWorkbench().getDisplay(), "Courier New", 10, SWT.BOLD);
- label.setFont(font);
- label.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED));
- label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
- label.setText(PREVIEW_DEFAULT_TITLE);
- label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
- }
-
- private Control getControl(PanelEnum panelId) {
- Control control = defaultComposite;
- if (panelId.equals(PanelEnum.BROWSER)) {
- control = browser;
- }
- return control;
- }
-
- public void setDisplay(final PanelEnum panelId) {
- Control control = getControl(panelId);
- stackLayout.topControl = control;
- stackedComposite.layout();
- stackedComposite.getParent().layout();
- getParent().layout();
- getParent().getParent().layout();
- }
-
- public void updatePreview(final PanelEnum panelId, final URI uri) {
- try {
- if (panelId.equals(PanelEnum.BROWSER)) {
- browser.setUrl(uri.toURL().toString());
- }
- } catch (Exception ex) {
- OseeLog.log(OteUiDefinePlugin.class, Level.SEVERE, String.format("Error Updating Preview [%s]", panelId), ex);
- }
- }
-}
+ +/** + * @author Roberto E. Escobar + */ +public class PreviewPanel extends Composite { + private static final String PREVIEW_DEFAULT_TITLE = "Preview Not Available"; + + public enum PanelEnum { + DEFAULT, + BROWSER; + } + + private Composite stackedComposite; + private StackLayout stackLayout; + private Composite defaultComposite; + private Browser browser; + + public PreviewPanel(Composite parent, int style) { + super(parent, style); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + this.setLayout(layout); + this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + createControl(this); + } + + private void createControl(Composite parent) { + stackedComposite = new Composite(parent, SWT.BORDER); + stackLayout = new StackLayout(); + stackLayout.marginWidth = 0; + stackLayout.marginHeight = 0; + stackedComposite.setLayout(stackLayout); + stackedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + createBrowserArea(stackedComposite); + createPreviewNotAllowed(stackedComposite); + } + + private void createBrowserArea(Composite parent) { + browser = new Browser(parent, SWT.EMBEDDED | SWT.BORDER); + browser.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); + browser.setBackground(Displays.getSystemColor(SWT.COLOR_GREEN)); + } + + private void createPreviewNotAllowed(Composite parent) { + defaultComposite = new Composite(parent, SWT.BORDER); + defaultComposite.setLayout(new GridLayout()); + defaultComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + defaultComposite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + + Label label = new Label(defaultComposite, SWT.NONE); + Font font = new Font(PlatformUI.getWorkbench().getDisplay(), "Courier New", 10, SWT.BOLD); + label.setFont(font); + label.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED)); + label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true)); + label.setText(PREVIEW_DEFAULT_TITLE); + label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + } + + private Control getControl(PanelEnum panelId) { + Control control = defaultComposite; + if (panelId.equals(PanelEnum.BROWSER)) { + control = browser; + } + return control; + } + + public void setDisplay(final PanelEnum panelId) { + Control control = getControl(panelId); + stackLayout.topControl = control; + stackedComposite.layout(); + stackedComposite.getParent().layout(); + getParent().layout(); + getParent().getParent().layout(); + } + + public void updatePreview(final PanelEnum panelId, final URI uri) { + try { + if (panelId.equals(PanelEnum.BROWSER)) { + browser.setUrl(uri.toURL().toString()); + } + } catch (Exception ex) { + OseeLog.log(OteUiDefinePlugin.class, Level.SEVERE, String.format("Error Updating Preview [%s]", panelId), ex); + } + } +} diff --git a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/reports/HttpReportRequest.java b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/reports/HttpReportRequest.java index 92140cc26a4..410f1fff885 100644 --- a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/reports/HttpReportRequest.java +++ b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/reports/HttpReportRequest.java @@ -8,8 +8,8 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.ote.ui.define.reports;
-
+package org.eclipse.osee.ote.ui.define.reports; + import java.net.URLEncoder; import java.util.ArrayList; import java.util.Arrays; @@ -26,6 +26,7 @@ import org.eclipse.osee.framework.core.client.server.IHttpServerRequest; import org.eclipse.osee.framework.core.exception.OseeStateException; import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.osee.ote.define.artifacts.TestRunOperator; import org.eclipse.osee.ote.ui.define.OteUiDefinePlugin; import org.eclipse.osee.ote.ui.define.reports.output.IReportWriter; @@ -33,133 +34,134 @@ import org.eclipse.osee.ote.ui.define.reports.output.OutputFactory; import org.eclipse.osee.ote.ui.define.reports.output.OutputFormat; import org.eclipse.osee.ote.ui.define.utilities.SelectionHelper; import org.eclipse.osee.ote.ui.define.views.TestRunView; -import org.eclipse.swt.widgets.Display; -
-/**
- * @author Roberto E. Escobar
- */
-public class HttpReportRequest implements IHttpServerRequest {
- private static final String REQUEST_TYPE = "GET.REPORT";
- private static final String REPORT_ID = "id";
- private static final String REPORT_FORMAT = "format";
- private static final String REPORT_SOURCE = "source";
- private static final String PREVIEW_SIZE = "preview";
-
- public String getRequestType() {
- return REQUEST_TYPE;
- }
-
- public static String getUrl(String id, String format, String source) throws OseeStateException {
- return getUrl(id, format, source, -1);
- }
-
- public static String getUrl(String id, String format, String source, int preview) throws OseeStateException {
- Map<String, String> parameters = new HashMap<String, String>();
- parameters.put(REPORT_ID, id);
- parameters.put(REPORT_FORMAT, format);
- parameters.put(REPORT_SOURCE, source);
- if (preview > -1) {
- parameters.put(PREVIEW_SIZE, Integer.toString(preview));
- }
- return HttpUrlBuilderClient.getInstance().getUrlForLocalSkynetHttpServer(HttpReportRequest.REQUEST_TYPE, parameters);
- }
-
- public void processRequest(HttpRequest httpRequest, HttpResponse httpResponse) {
- if (httpRequest.getOriginatingAddress().isLoopbackAddress()) {
- String reportId = httpRequest.getParameter(REPORT_ID);
- String format = httpRequest.getParameter(REPORT_FORMAT);
-
- try {
- OutputFormat outputFormat = OutputFormat.fromString(format);
- ITestRunReport report = ExtensionDefinedReports.getInstance().getReportGenerator(reportId);
- report.gatherData(new NullProgressMonitor(), getSourceData(httpRequest));
-
- IReportWriter writer = OutputFactory.getReportWriter(outputFormat);
- writer.writeTitle(report.getTitle());
- writer.writeHeader(report.getHeader());
- String[][] body = report.getBody();
- for (int index = 0; index < body.length; index++) {
- writer.writeRow(body[index]);
- }
- report.clear();
-
- if (outputFormat.equals(OutputFormat.HTML) != true) {
- httpResponse.setReponseHeader("Accept-Ranges", "bytes");
- httpResponse.setContentEncoding("ISO-8859-1");
- String fileName = URLEncoder.encode(OutputFactory.getOutputFilename(outputFormat, reportId), "UTF-8");
- httpResponse.setContentDisposition(String.format("attachment; filename=%s", fileName));
- }
- httpResponse.setContentType(OutputFactory.getContentType(outputFormat));
- httpResponse.sendResponseHeaders(200, writer.length());
- writer.writeToOutput(httpResponse.getOutputStream());
-
- } catch (Exception ex) {
- handleException(httpRequest, httpResponse, ex);
- }
- }
- }
-
- private TestRunOperator[] getSourceData(HttpRequest httpRequest) {
- String source = httpRequest.getParameter(REPORT_SOURCE);
-
- List<TestRunOperator> toReturn = new ArrayList<TestRunOperator>();
- if (source.equals("local")) {
- LocalSourceSelection selection = new LocalSourceSelection();
- Display.getDefault().asyncExec(selection);
- TestRunOperator[] data = selection.getArtifacts();
- addData(httpRequest, data, toReturn);
- }
- return toReturn.toArray(new TestRunOperator[toReturn.size()]);
- }
-
- private void addData(HttpRequest httpRequest, TestRunOperator[] source, List<TestRunOperator> destination) {
- String previewSize = httpRequest.getParameter(PREVIEW_SIZE);
- if (Strings.isValid(previewSize)) {
- int size = 5;
- try {
- size = Integer.parseInt(previewSize);
- } catch (Exception ex) {
- size = 5;
- }
- if (size > source.length) {
- size = source.length;
- }
- for (int index = 0; index < size; index++) {
- destination.add(source[index]);
- }
- } else {
- destination.addAll(Arrays.asList(source));
- }
- }
-
- private void handleException(HttpRequest httpRequest, HttpResponse httpResponse, Exception ex) {
- OseeLog.log(OteUiDefinePlugin.class, Level.SEVERE, "Exception occurred.", ex);
- }
-
- private final class LocalSourceSelection implements Runnable {
-
- private TestRunOperator[] artifacts;
- private boolean done = false;
-
- public TestRunOperator[] getArtifacts() {
- while (this.isDone() != true)
- ;
- return artifacts;
- }
-
- public void run() {
- done = false;
- List<TestRunOperator> toReturn = new ArrayList<TestRunOperator>();
- StructuredViewer viewer = TestRunView.getViewer();
- if (viewer != null) {
- toReturn.addAll(SelectionHelper.getInstance().getSelections(viewer));
- }
- artifacts = toReturn.toArray(new TestRunOperator[toReturn.size()]);
- done = true;
- }
-
- public boolean isDone() {
- return done;
- }
- }
-}
+ +/** + * @author Roberto E. Escobar + */ +public class HttpReportRequest implements IHttpServerRequest { + private static final String REQUEST_TYPE = "GET.REPORT"; + private static final String REPORT_ID = "id"; + private static final String REPORT_FORMAT = "format"; + private static final String REPORT_SOURCE = "source"; + private static final String PREVIEW_SIZE = "preview"; + + public String getRequestType() { + return REQUEST_TYPE; + } + + public static String getUrl(String id, String format, String source) throws OseeStateException { + return getUrl(id, format, source, -1); + } + + public static String getUrl(String id, String format, String source, int preview) throws OseeStateException { + Map<String, String> parameters = new HashMap<String, String>(); + parameters.put(REPORT_ID, id); + parameters.put(REPORT_FORMAT, format); + parameters.put(REPORT_SOURCE, source); + if (preview > -1) { + parameters.put(PREVIEW_SIZE, Integer.toString(preview)); + } + return HttpUrlBuilderClient.getInstance().getUrlForLocalSkynetHttpServer(HttpReportRequest.REQUEST_TYPE, + parameters); + } + + public void processRequest(HttpRequest httpRequest, HttpResponse httpResponse) { + if (httpRequest.getOriginatingAddress().isLoopbackAddress()) { + String reportId = httpRequest.getParameter(REPORT_ID); + String format = httpRequest.getParameter(REPORT_FORMAT); + + try { + OutputFormat outputFormat = OutputFormat.fromString(format); + ITestRunReport report = ExtensionDefinedReports.getInstance().getReportGenerator(reportId); + report.gatherData(new NullProgressMonitor(), getSourceData(httpRequest)); + + IReportWriter writer = OutputFactory.getReportWriter(outputFormat); + writer.writeTitle(report.getTitle()); + writer.writeHeader(report.getHeader()); + String[][] body = report.getBody(); + for (int index = 0; index < body.length; index++) { + writer.writeRow(body[index]); + } + report.clear(); + + if (outputFormat.equals(OutputFormat.HTML) != true) { + httpResponse.setReponseHeader("Accept-Ranges", "bytes"); + httpResponse.setContentEncoding("ISO-8859-1"); + String fileName = URLEncoder.encode(OutputFactory.getOutputFilename(outputFormat, reportId), "UTF-8"); + httpResponse.setContentDisposition(String.format("attachment; filename=%s", fileName)); + } + httpResponse.setContentType(OutputFactory.getContentType(outputFormat)); + httpResponse.sendResponseHeaders(200, writer.length()); + writer.writeToOutput(httpResponse.getOutputStream()); + + } catch (Exception ex) { + handleException(httpRequest, httpResponse, ex); + } + } + } + + private TestRunOperator[] getSourceData(HttpRequest httpRequest) { + String source = httpRequest.getParameter(REPORT_SOURCE); + + List<TestRunOperator> toReturn = new ArrayList<TestRunOperator>(); + if (source.equals("local")) { + LocalSourceSelection selection = new LocalSourceSelection(); + Displays.ensureInDisplayThread(selection); + TestRunOperator[] data = selection.getArtifacts(); + addData(httpRequest, data, toReturn); + } + return toReturn.toArray(new TestRunOperator[toReturn.size()]); + } + + private void addData(HttpRequest httpRequest, TestRunOperator[] source, List<TestRunOperator> destination) { + String previewSize = httpRequest.getParameter(PREVIEW_SIZE); + if (Strings.isValid(previewSize)) { + int size = 5; + try { + size = Integer.parseInt(previewSize); + } catch (Exception ex) { + size = 5; + } + if (size > source.length) { + size = source.length; + } + for (int index = 0; index < size; index++) { + destination.add(source[index]); + } + } else { + destination.addAll(Arrays.asList(source)); + } + } + + private void handleException(HttpRequest httpRequest, HttpResponse httpResponse, Exception ex) { + OseeLog.log(OteUiDefinePlugin.class, Level.SEVERE, "Exception occurred.", ex); + } + + private final class LocalSourceSelection implements Runnable { + + private TestRunOperator[] artifacts; + private boolean done = false; + + public TestRunOperator[] getArtifacts() { + while (this.isDone() != true) { + ; + } + return artifacts; + } + + public void run() { + done = false; + List<TestRunOperator> toReturn = new ArrayList<TestRunOperator>(); + StructuredViewer viewer = TestRunView.getViewer(); + if (viewer != null) { + toReturn.addAll(SelectionHelper.getInstance().getSelections(viewer)); + } + artifacts = toReturn.toArray(new TestRunOperator[toReturn.size()]); + done = true; + } + + public boolean isDone() { + return done; + } + } +} diff --git a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/XViewerDataManager.java b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/XViewerDataManager.java index 0b617214888..4081cb455b4 100644 --- a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/XViewerDataManager.java +++ b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/XViewerDataManager.java @@ -8,8 +8,8 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.ote.ui.define.viewers;
-
+package org.eclipse.osee.ote.ui.define.viewers; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -24,250 +24,251 @@ import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.model.Branch; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.osee.framework.ui.skynet.artifact.massEditor.MassXViewerFactory; +import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.osee.ote.define.artifacts.TestRunOperator; import org.eclipse.osee.ote.ui.define.viewers.data.ArtifactItem; import org.eclipse.osee.ote.ui.define.viewers.data.BranchItem; import org.eclipse.osee.ote.ui.define.viewers.data.DataItem; import org.eclipse.osee.ote.ui.define.viewers.data.ScriptItem; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.TreeItem; -
-/**
- * @author Roberto E. Escobar
- */
-public class XViewerDataManager {
-
- private final XViewer xViewer;
- private final List<DataItem> commitableItems;
- private final List<DataItem> uncommitableItems;
- private final Map<Branch, DataItem> branchMap;
- private final List<DataItem> backingData;
- private final Collection<IDataChangedListener> listeners;
- private boolean isInitialized;
-
- public XViewerDataManager(XViewer xViewer) {
- super();
- this.backingData = new ArrayList<DataItem>();
- this.isInitialized = false;
- this.xViewer = xViewer;
- this.branchMap = new HashMap<Branch, DataItem>();
- this.commitableItems = new ArrayList<DataItem>();
- this.uncommitableItems = new ArrayList<DataItem>();
- this.listeners = Collections.synchronizedSet(new HashSet<IDataChangedListener>());
- }
-
- private void ensureInitialized() {
- if (isInitialized != true) {
- isInitialized = true;
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- xViewer.setInput(backingData);
- }
- });
- }
- }
-
- public void addArtifacts(IProgressMonitor monitor, final List<Artifact> artifacts) throws OseeCoreException, AttributeDoesNotExist {
- if (branchMap.isEmpty()) {
- if (xViewer.getXViewerFactory() instanceof MassXViewerFactory) {
- ((MassXViewerFactory) xViewer.getXViewerFactory()).registerAllAttributeColumnsForArtifacts(artifacts, true);
- }
- }
- int total = artifacts.size();
- for (int index = 0; index < artifacts.size(); index++) {
- Artifact artifact = artifacts.get(index);
- monitor.subTask(String.format("Adding to Table: [%s] [%s of %s]", artifact.getName(), index + 1,
- total));
-
- DataItem branchItem = getBranchItem(artifact);
- DataItem scriptItem = getScriptItem(branchItem, artifact);
-
- ArtifactItem tempItem = new ArtifactItem(xViewer, artifact, null);
-
- DataItem itemFound = scriptItem.getChild(tempItem.getKey());
- if (itemFound == null) {
- scriptItem.addChild(tempItem.getKey(), tempItem);
- tempItem.setParent(scriptItem);
- TestRunOperator operator = tempItem.getOperator();
- if (operator.isFromLocalWorkspace()) {
- if (operator.isCommitAllowed()) {
- commitableItems.add(tempItem);
- } else {
- uncommitableItems.add(tempItem);
- }
- }
- }
- monitor.worked(1);
- }
-
- refresh();
- }
-
- private void refresh() {
- ensureInitialized();
- notifyOnDataChanged();
-
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- xViewer.refresh();
- };
- });
- }
-
- private DataItem getScriptItem(DataItem branchItem, Artifact artifact) throws OseeCoreException {
- TestRunOperator testRunArtifact = new TestRunOperator(artifact);
- DataItem tempItem = new ScriptItem(testRunArtifact.getScriptUrl(), testRunArtifact.getScriptRevision(), null);
- DataItem scriptItem = branchItem.getChild(tempItem.getKey());
- if (scriptItem == null) {
- scriptItem = tempItem;
- scriptItem.setParent(branchItem);
- branchItem.addChild(scriptItem.getKey(), scriptItem);
- }
- return scriptItem;
- }
-
- private DataItem getBranchItem(Artifact artifact) {
- Branch branch = artifact.getBranch();
- DataItem toReturn = branchMap.get(branch);
- if (toReturn == null) {
- toReturn = new BranchItem(branch, null);
- branchMap.put(branch, toReturn);
- backingData.add(toReturn);
- }
- return toReturn;
- }
-
- private void removeHelper(DataItem item) {
- if (item != null) {
- DataItem parent = item.getParent();
- if (parent != null) {
- parent.removeChild(item);
- if (parent.hasChildren() != true) {
- removeHelper(parent);
- parent.dispose();
- }
- } else {
- branchMap.remove(item.getKey());
- backingData.remove(item);
- }
- }
- }
-
- public void removeSelected() {
- List<DataItem> items = getSelected();
- for (DataItem item : items) {
- removeHelper(item);
- item.dispose();
- commitableItems.remove(item);
- uncommitableItems.remove(item);
- }
- refresh();
- }
-
- public void removeAll() {
- commitableItems.clear();
- uncommitableItems.clear();
- for (DataItem dataItem : branchMap.values()) {
- dataItem.dispose();
- }
- branchMap.clear();
- backingData.clear();
- refresh();
- }
-
- public Control getControl() {
- return xViewer.getTree();
- }
-
- private List<DataItem> getSelected() {
- List<DataItem> toReturn = new ArrayList<DataItem>();
- TreeItem items[] = xViewer.getTree().getSelection();
- if (items.length > 0) {
- for (TreeItem item : items) {
- toReturn.add((DataItem) item.getData());
- }
- }
- return toReturn;
- }
-
- public List<Artifact> getSelectedArtifacts() {
- List<Artifact> toReturn = new ArrayList<Artifact>();
- for (DataItem item : getSelected()) {
- Object object = item.getData();
- if (object instanceof Artifact) {
- toReturn.add((Artifact) object);
- }
- }
- return toReturn;
- }
-
- public Artifact[] getUnCommitable() {
- return getArtifactsFromDataItemList(uncommitableItems);
- }
-
- public Artifact[] getAllCommitable() {
- return getArtifactsFromDataItemList(commitableItems);
- }
-
- private Artifact[] getArtifactsFromDataItemList(List<DataItem> sourceList) {
- List<Artifact> toReturn = new ArrayList<Artifact>();
- for (DataItem item : sourceList) {
- toReturn.add((Artifact) (item.getData()));
- }
- return toReturn.toArray(new Artifact[toReturn.size()]);
- }
-
- public Artifact[] getSelectedForCommit() {
- List<Artifact> toReturn = new ArrayList<Artifact>();
- for (DataItem item : getSelected()) {
- if (commitableItems.contains(item)) {
- toReturn.add((Artifact) (item.getData()));
- }
- }
- return toReturn.toArray(new Artifact[toReturn.size()]);
- }
-
- public void removeFromCommitable(final Collection<Artifact> artifacts) {
- removeArtifactsFromDataItemList(commitableItems, artifacts);
- removeArtifactsFromDataItemList(uncommitableItems, artifacts);
- refresh();
- }
-
- private void removeArtifactsFromDataItemList(List<DataItem> sourceList, final Collection<Artifact> artifactsToRemove) {
- List<DataItem> itemsToRemove = new ArrayList<DataItem>();
- for (DataItem item : sourceList) {
- Object object = item.getData();
- if (artifactsToRemove.contains(object)) {
- itemsToRemove.add(item);
- }
- }
- sourceList.removeAll(itemsToRemove);
- }
-
- private void notifyOnDataChanged() {
- synchronized (listeners) {
- for (IDataChangedListener listener : listeners) {
- listener.onDataChanged();
- }
- }
- }
-
- public void registerListener(IDataChangedListener listener) {
- synchronized (listeners) {
- listeners.add(listener);
- }
- }
-
- public void deRegisterListener(IDataChangedListener listener) {
- synchronized (listeners) {
- if (listeners.contains(listener)) {
- listeners.remove(listener);
- }
- }
- }
-
- public boolean isEmpty() {
- return branchMap.isEmpty();
- }
-}
+ +/** + * @author Roberto E. Escobar + */ +public class XViewerDataManager { + + private final XViewer xViewer; + private final List<DataItem> commitableItems; + private final List<DataItem> uncommitableItems; + private final Map<Branch, DataItem> branchMap; + private final List<DataItem> backingData; + private final Collection<IDataChangedListener> listeners; + private boolean isInitialized; + + public XViewerDataManager(XViewer xViewer) { + super(); + this.backingData = new ArrayList<DataItem>(); + this.isInitialized = false; + this.xViewer = xViewer; + this.branchMap = new HashMap<Branch, DataItem>(); + this.commitableItems = new ArrayList<DataItem>(); + this.uncommitableItems = new ArrayList<DataItem>(); + this.listeners = Collections.synchronizedSet(new HashSet<IDataChangedListener>()); + } + + private void ensureInitialized() { + if (isInitialized != true) { + isInitialized = true; + Displays.ensureInDisplayThread(new Runnable() { + @Override + public void run() { + xViewer.setInput(backingData); + } + }); + } + } + + public void addArtifacts(IProgressMonitor monitor, final List<Artifact> artifacts) throws OseeCoreException, AttributeDoesNotExist { + if (branchMap.isEmpty()) { + if (xViewer.getXViewerFactory() instanceof MassXViewerFactory) { + ((MassXViewerFactory) xViewer.getXViewerFactory()).registerAllAttributeColumnsForArtifacts(artifacts, true); + } + } + int total = artifacts.size(); + for (int index = 0; index < artifacts.size(); index++) { + Artifact artifact = artifacts.get(index); + monitor.subTask(String.format("Adding to Table: [%s] [%s of %s]", artifact.getName(), index + 1, total)); + + DataItem branchItem = getBranchItem(artifact); + DataItem scriptItem = getScriptItem(branchItem, artifact); + + ArtifactItem tempItem = new ArtifactItem(xViewer, artifact, null); + + DataItem itemFound = scriptItem.getChild(tempItem.getKey()); + if (itemFound == null) { + scriptItem.addChild(tempItem.getKey(), tempItem); + tempItem.setParent(scriptItem); + TestRunOperator operator = tempItem.getOperator(); + if (operator.isFromLocalWorkspace()) { + if (operator.isCommitAllowed()) { + commitableItems.add(tempItem); + } else { + uncommitableItems.add(tempItem); + } + } + } + monitor.worked(1); + } + + refresh(); + } + + private void refresh() { + ensureInitialized(); + notifyOnDataChanged(); + + Displays.ensureInDisplayThread(new Runnable() { + @Override + public void run() { + xViewer.refresh(); + }; + }); + } + + private DataItem getScriptItem(DataItem branchItem, Artifact artifact) throws OseeCoreException { + TestRunOperator testRunArtifact = new TestRunOperator(artifact); + DataItem tempItem = new ScriptItem(testRunArtifact.getScriptUrl(), testRunArtifact.getScriptRevision(), null); + DataItem scriptItem = branchItem.getChild(tempItem.getKey()); + if (scriptItem == null) { + scriptItem = tempItem; + scriptItem.setParent(branchItem); + branchItem.addChild(scriptItem.getKey(), scriptItem); + } + return scriptItem; + } + + private DataItem getBranchItem(Artifact artifact) { + Branch branch = artifact.getBranch(); + DataItem toReturn = branchMap.get(branch); + if (toReturn == null) { + toReturn = new BranchItem(branch, null); + branchMap.put(branch, toReturn); + backingData.add(toReturn); + } + return toReturn; + } + + private void removeHelper(DataItem item) { + if (item != null) { + DataItem parent = item.getParent(); + if (parent != null) { + parent.removeChild(item); + if (parent.hasChildren() != true) { + removeHelper(parent); + parent.dispose(); + } + } else { + branchMap.remove(item.getKey()); + backingData.remove(item); + } + } + } + + public void removeSelected() { + List<DataItem> items = getSelected(); + for (DataItem item : items) { + removeHelper(item); + item.dispose(); + commitableItems.remove(item); + uncommitableItems.remove(item); + } + refresh(); + } + + public void removeAll() { + commitableItems.clear(); + uncommitableItems.clear(); + for (DataItem dataItem : branchMap.values()) { + dataItem.dispose(); + } + branchMap.clear(); + backingData.clear(); + refresh(); + } + + public Control getControl() { + return xViewer.getTree(); + } + + private List<DataItem> getSelected() { + List<DataItem> toReturn = new ArrayList<DataItem>(); + TreeItem items[] = xViewer.getTree().getSelection(); + if (items.length > 0) { + for (TreeItem item : items) { + toReturn.add((DataItem) item.getData()); + } + } + return toReturn; + } + + public List<Artifact> getSelectedArtifacts() { + List<Artifact> toReturn = new ArrayList<Artifact>(); + for (DataItem item : getSelected()) { + Object object = item.getData(); + if (object instanceof Artifact) { + toReturn.add((Artifact) object); + } + } + return toReturn; + } + + public Artifact[] getUnCommitable() { + return getArtifactsFromDataItemList(uncommitableItems); + } + + public Artifact[] getAllCommitable() { + return getArtifactsFromDataItemList(commitableItems); + } + + private Artifact[] getArtifactsFromDataItemList(List<DataItem> sourceList) { + List<Artifact> toReturn = new ArrayList<Artifact>(); + for (DataItem item : sourceList) { + toReturn.add((Artifact) (item.getData())); + } + return toReturn.toArray(new Artifact[toReturn.size()]); + } + + public Artifact[] getSelectedForCommit() { + List<Artifact> toReturn = new ArrayList<Artifact>(); + for (DataItem item : getSelected()) { + if (commitableItems.contains(item)) { + toReturn.add((Artifact) (item.getData())); + } + } + return toReturn.toArray(new Artifact[toReturn.size()]); + } + + public void removeFromCommitable(final Collection<Artifact> artifacts) { + removeArtifactsFromDataItemList(commitableItems, artifacts); + removeArtifactsFromDataItemList(uncommitableItems, artifacts); + refresh(); + } + + private void removeArtifactsFromDataItemList(List<DataItem> sourceList, final Collection<Artifact> artifactsToRemove) { + List<DataItem> itemsToRemove = new ArrayList<DataItem>(); + for (DataItem item : sourceList) { + Object object = item.getData(); + if (artifactsToRemove.contains(object)) { + itemsToRemove.add(item); + } + } + sourceList.removeAll(itemsToRemove); + } + + private void notifyOnDataChanged() { + synchronized (listeners) { + for (IDataChangedListener listener : listeners) { + listener.onDataChanged(); + } + } + } + + public void registerListener(IDataChangedListener listener) { + synchronized (listeners) { + listeners.add(listener); + } + } + + public void deRegisterListener(IDataChangedListener listener) { + synchronized (listeners) { + if (listeners.contains(listener)) { + listeners.remove(listener); + } + } + } + + public boolean isEmpty() { + return branchMap.isEmpty(); + } +} diff --git a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/actions/LaunchReportsAction.java b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/actions/LaunchReportsAction.java index ccb77e68893..c00f8ce48ca 100644 --- a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/actions/LaunchReportsAction.java +++ b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/actions/LaunchReportsAction.java @@ -8,49 +8,50 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.ote.ui.define.viewers.actions;
-
+package org.eclipse.osee.ote.ui.define.viewers.actions; + import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.window.Window; +import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.osee.ote.ui.define.dialogs.ReportsDialog; import org.eclipse.osee.ote.ui.define.utilities.EditorUtility; import org.eclipse.osee.ote.ui.define.utilities.SelectionHelper; -import org.eclipse.swt.widgets.Display; import org.eclipse.ui.PlatformUI; -
-/**
- * @author Roberto E. Escobar
- */
-public class LaunchReportsAction extends AbstractActionHandler {
-
- public LaunchReportsAction(StructuredViewer viewer, String text) throws Exception {
- super(viewer, text);
- }
-
- public LaunchReportsAction(StructuredViewer viewer, String text, ImageDescriptor image) throws Exception {
- super(viewer, text, image);
- }
-
- @Override
- public void run() {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- ReportsDialog dialog = new ReportsDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell());
- int result = dialog.open();
- if (result == Window.OK) {
- String reportId = dialog.getReportSelected();
- String format = dialog.getReportFormat();
- EditorUtility.openEditor(reportId, format);
- }
- }
- });
- }
-
- @Override
- public void updateState() {
- if (getViewer() != null) {
- setEnabled(SelectionHelper.getInstance().getSelections(getViewer()).size() > 0);
- }
- }
-}
+ +/** + * @author Roberto E. Escobar + */ +public class LaunchReportsAction extends AbstractActionHandler { + + public LaunchReportsAction(StructuredViewer viewer, String text) throws Exception { + super(viewer, text); + } + + public LaunchReportsAction(StructuredViewer viewer, String text, ImageDescriptor image) throws Exception { + super(viewer, text, image); + } + + @Override + public void run() { + Displays.ensureInDisplayThread(new Runnable() { + @Override + public void run() { + ReportsDialog dialog = new ReportsDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell()); + int result = dialog.open(); + if (result == Window.OK) { + String reportId = dialog.getReportSelected(); + String format = dialog.getReportFormat(); + EditorUtility.openEditor(reportId, format); + } + } + }); + } + + @Override + public void updateState() { + if (getViewer() != null) { + setEnabled(SelectionHelper.getInstance().getSelections(getViewer()).size() > 0); + } + } +} diff --git a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/actions/OpenAssociatedOutfile.java b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/actions/OpenAssociatedOutfile.java index 31b15d657bd..d0aef4694cc 100644 --- a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/actions/OpenAssociatedOutfile.java +++ b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/actions/OpenAssociatedOutfile.java @@ -8,8 +8,8 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.ote.ui.define.viewers.actions;
-
+package org.eclipse.osee.ote.ui.define.viewers.actions; + import java.net.URI; import java.util.logging.Level; import org.eclipse.core.filesystem.EFS; @@ -17,61 +17,62 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.framework.ui.swt.Displays; import org.eclipse.osee.ote.define.artifacts.TestRunOperator; import org.eclipse.osee.ote.ui.define.OteUiDefinePlugin; import org.eclipse.osee.ote.ui.define.utilities.SelectionHelper; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ide.IDE; -
-/**
- * @author Roberto E. Escobar
- */
-public class OpenAssociatedOutfile extends AbstractActionHandler {
-
- public OpenAssociatedOutfile(StructuredViewer viewer, String text) throws Exception {
- super(viewer, text);
- }
-
- public OpenAssociatedOutfile(StructuredViewer viewer, String text, ImageDescriptor image) throws Exception {
- super(viewer, text, image);
- }
-
- @Override
- public void updateState() {
- TestRunOperator artifact = SelectionHelper.getInstance().getSelection(getViewer());
- setEnabled(artifact != null);
- }
-
- @Override
- public void run() {
- TestRunOperator operator = SelectionHelper.getInstance().getSelection(getViewer());
- try {
- String targetFile = operator.getOutfileUrl();
- openEditorUtility(new URI(targetFile));
- } catch (Exception ex) {
- handleException(ex);
- }
- }
-
- private void openEditorUtility(final URI resource) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- try {
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IDE.openEditorOnFileStore(page, EFS.getStore(resource));
- } catch (Exception ex) {
- handleException(ex);
- }
- }
- });
- }
-
- private void handleException(Exception ex) {
- OseeLog.log(OteUiDefinePlugin.class, Level.WARNING, "Unable to open outfile.", ex);
- Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
- MessageDialog.openError(shell, "Open Outfile", "Unable to open outfile.");
- }
+ +/** + * @author Roberto E. Escobar + */ +public class OpenAssociatedOutfile extends AbstractActionHandler { + + public OpenAssociatedOutfile(StructuredViewer viewer, String text) throws Exception { + super(viewer, text); + } + + public OpenAssociatedOutfile(StructuredViewer viewer, String text, ImageDescriptor image) throws Exception { + super(viewer, text, image); + } + + @Override + public void updateState() { + TestRunOperator artifact = SelectionHelper.getInstance().getSelection(getViewer()); + setEnabled(artifact != null); + } + + @Override + public void run() { + TestRunOperator operator = SelectionHelper.getInstance().getSelection(getViewer()); + try { + String targetFile = operator.getOutfileUrl(); + openEditorUtility(new URI(targetFile)); + } catch (Exception ex) { + handleException(ex); + } + } + + private void openEditorUtility(final URI resource) { + Displays.ensureInDisplayThread(new Runnable() { + @Override + public void run() { + try { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + IDE.openEditorOnFileStore(page, EFS.getStore(resource)); + } catch (Exception ex) { + handleException(ex); + } + } + }); + } + + private void handleException(Exception ex) { + OseeLog.log(OteUiDefinePlugin.class, Level.WARNING, "Unable to open outfile.", ex); + Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell(); + MessageDialog.openError(shell, "Open Outfile", "Unable to open outfile."); + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/data/ArtifactItem.java b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/data/ArtifactItem.java index 6f166679e34..bde10c7d19e 100644 --- a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/data/ArtifactItem.java +++ b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/viewers/data/ArtifactItem.java @@ -32,8 +32,8 @@ import org.eclipse.osee.framework.skynet.core.event.Sender; import org.eclipse.osee.framework.skynet.core.event2.ArtifactEvent;
import org.eclipse.osee.framework.skynet.core.event2.artifact.IArtifactEventListener;
import org.eclipse.osee.framework.skynet.core.event2.filter.IEventFilter;
-import org.eclipse.osee.framework.ui.plugin.util.Displays;
import org.eclipse.osee.framework.ui.skynet.ArtifactImageManager;
+import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.osee.framework.ui.swt.OverlayImage;
import org.eclipse.osee.framework.ui.swt.OverlayImage.Location;
diff --git a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/views/TestRunView.java b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/views/TestRunView.java index 3a831743d9f..0728ec1add3 100644 --- a/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/views/TestRunView.java +++ b/plugins/org.eclipse.osee.ote.ui.define/src/org/eclipse/osee/ote/ui/define/views/TestRunView.java @@ -27,7 +27,7 @@ import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.plugin.core.IActionable;
import org.eclipse.osee.framework.ui.plugin.OseeUiActions;
import org.eclipse.osee.framework.ui.plugin.PluginUiImage;
-import org.eclipse.osee.framework.ui.plugin.util.Displays;
+import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.osee.ote.ui.define.OteDefineImage;
import org.eclipse.osee.ote.ui.define.OteUiDefinePlugin;
@@ -42,7 +42,6 @@ import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PlatformUI;
@@ -53,227 +52,229 @@ import org.eclipse.ui.part.ViewPart; * @author Roberto E. Escobar
*/
public class TestRunView extends ViewPart implements IActionable, IDataChangedListener {
- public static final String VIEW_ID = TestRunView.class.getName();
- private static final String BEGIN_MESSAGE =
- "To begin, drag and drop a test run artifact from artifact explorer or from an artifact search result window. Alternatively, you can drag and drop a test outfile onto this view.";
-
- private Action expandAction, collapseAction, refreshAction;
- private static TestRunXViewer viewer = null;
- @SuppressWarnings("unused")
- private IHandlerService handlerService;
- private ShowOnlyLatestRuns latestRunFilter;
- private boolean isFilterOn;
-
- // private static final String FLAT_KEY = "flat";
-
- @Override
- public void createPartControl(Composite parent) {
- parent.setLayout(new GridLayout());
-
- PlatformUI.getWorkbench().getService(IHandlerService.class);
- handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
-
- viewer = new TestRunXViewer(parent);
- Tree tree = viewer.getTree();
- GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- gridData.minimumHeight = 350;
- tree.setLayoutData(gridData);
- tree.setHeaderVisible(true);
- tree.setLinesVisible(true);
- tree.setFont(parent.getFont());
-
- parent.layout();
- createActions();
- createMenus();
- createToolbar();
-
- latestRunFilter = new ShowOnlyLatestRuns();
- isFilterOn = false;
- viewer.registerListener(this);
- viewer.getTree().addKeyListener(new KeyAdapter() {
-
- @Override
- public void keyPressed(KeyEvent event) {
- if (event.stateMask == SWT.CTRL && (event.keyCode == 'A' || event.keyCode == 'a')) {
- Object object = event.getSource();
- if (object instanceof Tree) {
- Tree tree = (Tree) object;
- tree.selectAll();
- }
- }
- }
- });
- onDataChanged();
-
- PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, "org.eclipse.osee.ote.ui.define.testRunView");
- }
-
- @Override
- public void setFocus() {
- }
-
- public String getActionDescription() {
- return "";
- }
-
- protected void createActions() {
- expandAction = new Action("Expand All") {
-
- @Override
- public void run() {
- viewer.getTree().setRedraw(false);
- viewer.expandAll();
- viewer.getTree().setRedraw(true);
- }
- };
- expandAction.setImageDescriptor(ImageManager.getImageDescriptor(OteDefineImage.EXPAND_STATE));
- expandAction.setToolTipText("Expand All");
-
- collapseAction = new Action("Collapse All") {
-
- @Override
- public void run() {
- viewer.getTree().setRedraw(false);
- viewer.collapseAll();
- viewer.getTree().setRedraw(true);
- }
- };
- collapseAction.setImageDescriptor(ImageManager.getImageDescriptor(OteDefineImage.COLLAPSE_STATE));
- collapseAction.setToolTipText("Collapse All");
-
- refreshAction = new Action("Refresh") {
-
- @Override
- public void run() {
- Displays.ensureInDisplayThread(new Runnable() {
- public void run() {
- viewer.refresh();
- };
- });
- }
- };
- refreshAction.setToolTipText("Refresh Table");
- refreshAction.setImageDescriptor(ImageManager.getImageDescriptor(PluginUiImage.REFRESH));
-
- }
-
- private void createMenus() {
- MenuManager menuManager = new MenuManager();
- getSite().registerContextMenu(VIEW_ID, menuManager, viewer);
- menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
- menuManager.setParent(getViewSite().getActionBars().getMenuManager());
- fillMenu(menuManager);
- getSite().setSelectionProvider(viewer);
- OseeUiActions.addBugToViewToolbar(this, this, OteUiDefinePlugin.getInstance(), VIEW_ID, "Test Run View");
- }
-
- private void fillMenu(IMenuManager menuManager) {
- menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
- }
-
- private void createToolbar() {
- IToolBarManager toolbarManager = getViewSite().getActionBars().getToolBarManager();
- toolbarManager.add(refreshAction);
- toolbarManager.add(expandAction);
- toolbarManager.add(collapseAction);
- }
-
- public void setDescription(final String message) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- setContentDescription(message);
- }
- });
- }
-
- public void onDataChanged() {
- String message = BEGIN_MESSAGE;
- Object object = viewer.getInput();
- if (object != null && object instanceof Collection<?>) {
- if (!((Collection<?>) object).isEmpty()) {
- message = "";
- }
- }
- setDescription(message);
- }
-
- public static StructuredViewer getViewer() {
- return viewer;
- }
-
- public void presentGroupedByBranch() {
- BranchItem.setGroupModeEnabled(true);
- viewer.refresh();
- }
-
- public void presentGroupedByScript() {
- BranchItem.setGroupModeEnabled(false);
- viewer.refresh();
- }
-
- public void presentWithShortNames() {
- ScriptItem.setFullDescriptionModeEnabled(false);
- ArtifactItem.setFullDescriptionModeEnabled(false);
- viewer.refresh();
- }
-
- public void presentWithLongNames() {
- ScriptItem.setFullDescriptionModeEnabled(true);
- ArtifactItem.setFullDescriptionModeEnabled(true);
- viewer.refresh();
- }
-
- public void toggleFilter() {
- latestRunFilter.clear();
- if (isFilterOn != true) {
- isFilterOn = true;
- viewer.addFilter(latestRunFilter);
- } else {
- isFilterOn = false;
- viewer.removeFilter(latestRunFilter);
- }
- viewer.refresh();
- }
-
- private final class ShowOnlyLatestRuns extends ViewerFilter {
- private final Map<String, ArtifactItem> latestMap = new HashMap<String, ArtifactItem>();
-
- @Override
- public Object[] filter(Viewer viewer, Object parent, Object[] elements) {
- return super.filter(viewer, parent, elements);
- }
-
- @Override
- public boolean select(Viewer viewer, Object parentElement, Object element) {
- boolean toReturn = false;
- if (element instanceof ArtifactItem) {
- ArtifactItem item1 = (ArtifactItem) element;
- String name = item1.getOperator().getDescriptiveName();
-
- ArtifactItem item2 = latestMap.get(name);
- if (item2 == null) {
- latestMap.put(name, item1);
- toReturn = true;
- } else {
- try {
- Date date1 = item1.getOperator().getEndDate();
- Date date2 = item2.getOperator().getEndDate();
- if (date1.after(date2) || date1.equals(date2)) {
- latestMap.put(name, item1);
- toReturn = true;
- }
- } catch (Exception ex) {
- OseeLog.log(OteUiDefinePlugin.class, Level.WARNING, "Error comparing run dates.", ex);
- }
- }
- } else {
- toReturn = true;
- }
- return toReturn;
- }
-
- public void clear() {
- latestMap.clear();
- }
- }
+ public static final String VIEW_ID = TestRunView.class.getName();
+ private static final String BEGIN_MESSAGE =
+ "To begin, drag and drop a test run artifact from artifact explorer or from an artifact search result window. Alternatively, you can drag and drop a test outfile onto this view.";
+
+ private Action expandAction, collapseAction, refreshAction;
+ private static TestRunXViewer viewer = null;
+ @SuppressWarnings("unused")
+ private IHandlerService handlerService;
+ private ShowOnlyLatestRuns latestRunFilter;
+ private boolean isFilterOn;
+
+ // private static final String FLAT_KEY = "flat";
+
+ @Override
+ public void createPartControl(Composite parent) {
+ parent.setLayout(new GridLayout());
+
+ PlatformUI.getWorkbench().getService(IHandlerService.class);
+ handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
+
+ viewer = new TestRunXViewer(parent);
+ Tree tree = viewer.getTree();
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gridData.minimumHeight = 350;
+ tree.setLayoutData(gridData);
+ tree.setHeaderVisible(true);
+ tree.setLinesVisible(true);
+ tree.setFont(parent.getFont());
+
+ parent.layout();
+ createActions();
+ createMenus();
+ createToolbar();
+
+ latestRunFilter = new ShowOnlyLatestRuns();
+ isFilterOn = false;
+ viewer.registerListener(this);
+ viewer.getTree().addKeyListener(new KeyAdapter() {
+
+ @Override
+ public void keyPressed(KeyEvent event) {
+ if (event.stateMask == SWT.CTRL && (event.keyCode == 'A' || event.keyCode == 'a')) {
+ Object object = event.getSource();
+ if (object instanceof Tree) {
+ Tree tree = (Tree) object;
+ tree.selectAll();
+ }
+ }
+ }
+ });
+ onDataChanged();
+
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, "org.eclipse.osee.ote.ui.define.testRunView");
+ }
+
+ @Override
+ public void setFocus() {
+ }
+
+ public String getActionDescription() {
+ return "";
+ }
+
+ protected void createActions() {
+ expandAction = new Action("Expand All") {
+
+ @Override
+ public void run() {
+ viewer.getTree().setRedraw(false);
+ viewer.expandAll();
+ viewer.getTree().setRedraw(true);
+ }
+ };
+ expandAction.setImageDescriptor(ImageManager.getImageDescriptor(OteDefineImage.EXPAND_STATE));
+ expandAction.setToolTipText("Expand All");
+
+ collapseAction = new Action("Collapse All") {
+
+ @Override
+ public void run() {
+ viewer.getTree().setRedraw(false);
+ viewer.collapseAll();
+ viewer.getTree().setRedraw(true);
+ }
+ };
+ collapseAction.setImageDescriptor(ImageManager.getImageDescriptor(OteDefineImage.COLLAPSE_STATE));
+ collapseAction.setToolTipText("Collapse All");
+
+ refreshAction = new Action("Refresh") {
+
+ @Override
+ public void run() {
+ Displays.ensureInDisplayThread(new Runnable() {
+ public void run() {
+ viewer.refresh();
+ };
+ });
+ }
+ };
+ refreshAction.setToolTipText("Refresh Table");
+ refreshAction.setImageDescriptor(ImageManager.getImageDescriptor(PluginUiImage.REFRESH));
+
+ }
+
+ private void createMenus() {
+ MenuManager menuManager = new MenuManager();
+ getSite().registerContextMenu(VIEW_ID, menuManager, viewer);
+ menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ menuManager.setParent(getViewSite().getActionBars().getMenuManager());
+ fillMenu(menuManager);
+ getSite().setSelectionProvider(viewer);
+ OseeUiActions.addBugToViewToolbar(this, this, OteUiDefinePlugin.getInstance(), VIEW_ID, "Test Run View");
+ }
+
+ private void fillMenu(IMenuManager menuManager) {
+ menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ }
+
+ private void createToolbar() {
+ IToolBarManager toolbarManager = getViewSite().getActionBars().getToolBarManager();
+ toolbarManager.add(refreshAction);
+ toolbarManager.add(expandAction);
+ toolbarManager.add(collapseAction);
+ }
+
+ public void setDescription(final String message) {
+ Displays.ensureInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ setContentDescription(message);
+ }
+ });
+ }
+
+ @Override
+ public void onDataChanged() {
+ String message = BEGIN_MESSAGE;
+ Object object = viewer.getInput();
+ if (object != null && object instanceof Collection<?>) {
+ if (!((Collection<?>) object).isEmpty()) {
+ message = "";
+ }
+ }
+ setDescription(message);
+ }
+
+ public static StructuredViewer getViewer() {
+ return viewer;
+ }
+
+ public void presentGroupedByBranch() {
+ BranchItem.setGroupModeEnabled(true);
+ viewer.refresh();
+ }
+
+ public void presentGroupedByScript() {
+ BranchItem.setGroupModeEnabled(false);
+ viewer.refresh();
+ }
+
+ public void presentWithShortNames() {
+ ScriptItem.setFullDescriptionModeEnabled(false);
+ ArtifactItem.setFullDescriptionModeEnabled(false);
+ viewer.refresh();
+ }
+
+ public void presentWithLongNames() {
+ ScriptItem.setFullDescriptionModeEnabled(true);
+ ArtifactItem.setFullDescriptionModeEnabled(true);
+ viewer.refresh();
+ }
+
+ public void toggleFilter() {
+ latestRunFilter.clear();
+ if (isFilterOn != true) {
+ isFilterOn = true;
+ viewer.addFilter(latestRunFilter);
+ } else {
+ isFilterOn = false;
+ viewer.removeFilter(latestRunFilter);
+ }
+ viewer.refresh();
+ }
+
+ private final class ShowOnlyLatestRuns extends ViewerFilter {
+ private final Map<String, ArtifactItem> latestMap = new HashMap<String, ArtifactItem>();
+
+ @Override
+ public Object[] filter(Viewer viewer, Object parent, Object[] elements) {
+ return super.filter(viewer, parent, elements);
+ }
+
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ boolean toReturn = false;
+ if (element instanceof ArtifactItem) {
+ ArtifactItem item1 = (ArtifactItem) element;
+ String name = item1.getOperator().getDescriptiveName();
+
+ ArtifactItem item2 = latestMap.get(name);
+ if (item2 == null) {
+ latestMap.put(name, item1);
+ toReturn = true;
+ } else {
+ try {
+ Date date1 = item1.getOperator().getEndDate();
+ Date date2 = item2.getOperator().getEndDate();
+ if (date1.after(date2) || date1.equals(date2)) {
+ latestMap.put(name, item1);
+ toReturn = true;
+ }
+ } catch (Exception ex) {
+ OseeLog.log(OteUiDefinePlugin.class, Level.WARNING, "Error comparing run dates.", ex);
+ }
+ }
+ } else {
+ toReturn = true;
+ }
+ return toReturn;
+ }
+
+ public void clear() {
+ latestMap.clear();
+ }
+ }
}
|