diff options
author | ddunne | 2009-08-12 00:23:59 +0000 |
---|---|---|
committer | ddunne | 2009-08-12 00:23:59 +0000 |
commit | b02bebd023cce41a71b91f8ea42f5639b7a5d36a (patch) | |
tree | 6cda15f4802095286392b5f5728177b458211a41 | |
parent | c01e127ca49be8c3507f5623c51441ea1df68545 (diff) | |
download | org.eclipse.osee-b02bebd023cce41a71b91f8ea42f5639b7a5d36a.tar.gz org.eclipse.osee-b02bebd023cce41a71b91f8ea42f5639b7a5d36a.tar.xz org.eclipse.osee-b02bebd023cce41a71b91f8ea42f5639b7a5d36a.zip |
"Team Workflow" - ZPDTX - "Allow ability for tasks to set deadline date and have icons change appropriately"
8 files changed, 427 insertions, 346 deletions
diff --git a/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewer.java b/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewer.java index da109ed23b3..285cf3ab8a6 100644 --- a/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewer.java +++ b/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewer.java @@ -11,7 +11,9 @@ package org.eclipse.nebula.widgets.xviewer;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import java.util.logging.Level;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
@@ -23,6 +25,7 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.nebula.widgets.xviewer.column.XViewerDaysTillTodayColumn;
import org.eclipse.nebula.widgets.xviewer.customize.ColumnFilterDataUI;
import org.eclipse.nebula.widgets.xviewer.customize.CustomizeManager;
import org.eclipse.nebula.widgets.xviewer.customize.FilterDataUI;
@@ -110,6 +113,26 @@ public class XViewer extends TreeViewer { setupCtrlKeyListener();
}
+ private static List<XViewerComputedColumn> computedColumns;
+
+ public Collection<XViewerComputedColumn> getComputedColumns() {
+ if (computedColumns == null) {
+ computedColumns = new ArrayList<XViewerComputedColumn>();
+ computedColumns.add(new XViewerDaysTillTodayColumn());
+ }
+ return computedColumns;
+ }
+
+ public Collection<XViewerComputedColumn> getComputedColumns(XViewerColumn xCol) {
+ List<XViewerComputedColumn> matchCols = new ArrayList<XViewerComputedColumn>();
+ for (XViewerColumn computedCol : getComputedColumns()) {
+ if (((XViewerComputedColumn) computedCol).isApplicableFor(xCol)) {
+ matchCols.add((XViewerComputedColumn) computedCol);
+ }
+ }
+ return matchCols;
+ }
+
public void dispose() {
if (searchDataUI != null) searchDataUI.dispose();
if (filterDataUI != null) filterDataUI.dispose();
diff --git a/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerComputedColumn.java b/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerComputedColumn.java new file mode 100644 index 00000000000..4a68ea13fee --- /dev/null +++ b/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewerComputedColumn.java @@ -0,0 +1,46 @@ +/*
+ * Created on Aug 10, 2009
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.nebula.widgets.xviewer;
+
+/**
+ * @author Donald G. Dunne
+ */
+public abstract class XViewerComputedColumn extends XViewerValueColumn {
+
+ protected XViewerColumn sourceXViewerColumn;
+ protected XViewer xViewer;
+
+ public XViewerComputedColumn(String id, String name, int width, int align, boolean show, SortDataType sortDataType, boolean multiColumnEditable, String description) {
+ super(id, name, width, align, show, sortDataType, multiColumnEditable, description);
+ }
+
+ public XViewerComputedColumn(XViewer viewer, String xml) {
+ super(viewer, xml);
+ }
+
+ public XViewerColumn getSourceXViewerColumn() {
+ return sourceXViewerColumn;
+ }
+
+ public void setSourceXViewerColumn(XViewerColumn sourceXViewerColumn) {
+ this.sourceXViewerColumn = sourceXViewerColumn;
+ }
+
+ public abstract boolean isApplicableFor(XViewerColumn xViewerColumn);
+
+ public XViewer getXViewer() {
+ return xViewer;
+ }
+
+ @Override
+ public void setXViewer(XViewer xViewer) {
+ this.xViewer = xViewer;
+ }
+
+ @Override
+ public abstract XViewerComputedColumn copy();
+
+}
diff --git a/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/column/XViewerDaysTillTodayColumn.java b/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/column/XViewerDaysTillTodayColumn.java new file mode 100644 index 00000000000..4ed2cae003e --- /dev/null +++ b/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/column/XViewerDaysTillTodayColumn.java @@ -0,0 +1,106 @@ +/*
+ * Created on Aug 10, 2009
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.nebula.widgets.xviewer.column;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.logging.Level;
+import org.eclipse.nebula.widgets.xviewer.Activator;
+import org.eclipse.nebula.widgets.xviewer.XViewerColumn;
+import org.eclipse.nebula.widgets.xviewer.XViewerComputedColumn;
+import org.eclipse.nebula.widgets.xviewer.XViewerLabelProvider;
+import org.eclipse.nebula.widgets.xviewer.util.XViewerException;
+import org.eclipse.nebula.widgets.xviewer.util.internal.XViewerLib;
+import org.eclipse.nebula.widgets.xviewer.util.internal.XViewerLog;
+import org.eclipse.swt.SWT;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class XViewerDaysTillTodayColumn extends XViewerComputedColumn {
+
+ private final static SimpleDateFormat format10 = new SimpleDateFormat("MM/dd/yyyy");
+
+ public XViewerDaysTillTodayColumn() {
+ super("ats.computed.daysTillToday", "Days Till Today", 30, SWT.LEFT, false, SortDataType.Integer, false,
+ "Shows number of days till today for selected column");
+ }
+
+ @Override
+ public String getColumnText(Object element, XViewerColumn column, int columnIndex) throws XViewerException {
+ if (sourceXViewerColumn == null) {
+ return "Source column not set";
+ }
+ try {
+ String dateStr =
+ ((XViewerLabelProvider) xViewer.getLabelProvider()).getColumnText(element, sourceXViewerColumn,
+ columnIndex);
+ if (dateStr == null || dateStr.equals("")) {
+ return "";
+ }
+ DateFormat format;
+ if (dateStr.length() == 10) {
+ format = format10;
+ } else {
+ format = SimpleDateFormat.getInstance();
+ }
+ Date date1Date = null;
+ try {
+ date1Date = format.parse(dateStr);
+ } catch (ParseException ex) {
+ try {
+ date1Date = SimpleDateFormat.getInstance().parse(dateStr);
+ } catch (ParseException ex2) {
+ XViewerLog.log(Activator.class, Level.SEVERE, ex2);
+ }
+ }
+ if (date1Date == null) {
+ return "Can't parse date";
+ }
+ return String.valueOf(XViewerLib.daysTillToday(date1Date));
+ } catch (Exception ex) {
+ return ex.getLocalizedMessage();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.nebula.widgets.xviewer.XViewerComputedColumn#isApplicableFor(org.eclipse.nebula.widgets.xviewer.XViewerColumn)
+ */
+ @Override
+ public boolean isApplicableFor(XViewerColumn xViewerColumn) {
+ return xViewerColumn.getSortDataType() == SortDataType.Date;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.nebula.widgets.xviewer.XViewerColumn#getName()
+ */
+ @Override
+ public String getName() {
+ return super.getName() + " from " + sourceXViewerColumn.getName() + "";
+ }
+
+ @Override
+ public XViewerDaysTillTodayColumn copy() {
+ XViewerDaysTillTodayColumn col = new XViewerDaysTillTodayColumn();
+ col.setXViewer(getXViewer());
+ col.setSourceXViewerColumn(getSourceXViewerColumn());
+ return col;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.nebula.widgets.xviewer.XViewerColumn#getId()
+ */
+ @Override
+ public String getId() {
+ if (sourceXViewerColumn == null) {
+ return super.getId();
+ }
+ return super.getId() + "(" + sourceXViewerColumn.getId() + ")";
+ }
+
+}
diff --git a/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/customize/Snippet311.java b/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/customize/Snippet311.java deleted file mode 100644 index 2bff665f6ab..00000000000 --- a/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/customize/Snippet311.java +++ /dev/null @@ -1,140 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.nebula.widgets.xviewer.customize;
-
-/*
- * Table example snippet: show a menu in a table header
- *
- * For a list of all SWT example snippets see
- * http://www.eclipse.org/swt/snippets/
- *
- * @since 3.5
- */
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
-
-public class Snippet311 {
-
- static String[][] files =
- { {"ver.txt", "1 KB", "Text Document", "28/09/2005 9:57 AM", "admin",},
- {"Thumbs.db", "76 KB", "Data Base file", "13/03/2006 3:56 PM", "john",},
- {"daddy.bmp", "148 MB", "Bitmap", "27/10/2008 1:34 PM", "bill",},
- {"io.sys", "48 KB", "File System", "16/12/2008 6:14 AM", "admin",},
- {"Programs", "0 KB", "File Folder", "04/02/2009 12:18 PM", "anne",},
- {"test.rnd", "55 MB", "RND File", "19/02/2009 5:49 PM", "john",},
- {"arial.ttf", "94 KB", "True Type Font", "25/08/2008 1:25 PM", "john",},};
-
- static void createMenuItem(Menu parent, final TableColumn column) {
- final MenuItem itemName = new MenuItem(parent, SWT.CHECK);
- itemName.setText(column.getText());
- itemName.setSelection(column.getResizable());
- itemName.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- if (itemName.getSelection()) {
- column.setWidth(150);
- column.setResizable(true);
- } else {
- column.setWidth(0);
- column.setResizable(false);
- }
- }
- });
- }
-
- public static void main(String[] args) {
- final Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
-
- final Table table = new Table(shell, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
- table.setHeaderVisible(true);
- final Menu headerMenu = new Menu(shell, SWT.POP_UP);
- final TableColumn columnName = new TableColumn(table, SWT.NONE);
- columnName.setText("Name");
- columnName.setWidth(150);
- createMenuItem(headerMenu, columnName);
- final TableColumn columnSize = new TableColumn(table, SWT.NONE);
- columnSize.setText("Size");
- columnSize.setWidth(150);
- createMenuItem(headerMenu, columnSize);
- final TableColumn columnType = new TableColumn(table, SWT.NONE);
- columnType.setText("Type");
- columnType.setWidth(150);
- createMenuItem(headerMenu, columnType);
- final TableColumn columnDate = new TableColumn(table, SWT.NONE);
- columnDate.setText("Date");
- columnDate.setWidth(150);
- createMenuItem(headerMenu, columnDate);
- final TableColumn columnOwner = new TableColumn(table, SWT.NONE);
- columnOwner.setText("Owner");
- columnOwner.setWidth(0);
- columnOwner.setResizable(false);
- createMenuItem(headerMenu, columnOwner);
-
- for (int i = 0; i < files.length; i++) {
- TableItem item = new TableItem(table, SWT.NONE);
- item.setText(files[i]);
- }
-
- final Menu tableMenu = new Menu(shell, SWT.POP_UP);
- MenuItem item = new MenuItem(tableMenu, SWT.PUSH);
- item.setText("Open");
- item = new MenuItem(tableMenu, SWT.PUSH);
- item.setText("Open With");
- new MenuItem(tableMenu, SWT.SEPARATOR);
- item = new MenuItem(tableMenu, SWT.PUSH);
- item.setText("Cut");
- item = new MenuItem(tableMenu, SWT.PUSH);
- item.setText("Copy");
- item = new MenuItem(tableMenu, SWT.PUSH);
- item.setText("Paste");
- new MenuItem(tableMenu, SWT.SEPARATOR);
- item = new MenuItem(tableMenu, SWT.PUSH);
- item.setText("Delete");
-
- table.addListener(SWT.MenuDetect, new Listener() {
- public void handleEvent(Event event) {
- Point pt = display.map(null, table, new Point(event.x, event.y));
- Rectangle clientArea = table.getClientArea();
- boolean header = clientArea.y <= pt.y && pt.y < (clientArea.y + table.getHeaderHeight());
- table.setMenu(header ? headerMenu : tableMenu);
- }
- });
-
- /* IMPORTANT: Dispose the menus (only the current menu, set with setMenu(), will be automatically disposed) */
- table.addListener(SWT.Dispose, new Listener() {
- public void handleEvent(Event event) {
- headerMenu.dispose();
- tableMenu.dispose();
- }
- });
-
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- display.dispose();
- }
-}
diff --git a/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/customize/XViewerCustomMenu.java b/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/customize/XViewerCustomMenu.java index 54cc0944242..f47e58b8e2d 100644 --- a/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/customize/XViewerCustomMenu.java +++ b/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/customize/XViewerCustomMenu.java @@ -34,6 +34,7 @@ import org.eclipse.nebula.widgets.xviewer.XViewer; import org.eclipse.nebula.widgets.xviewer.XViewerColumn; import org.eclipse.nebula.widgets.xviewer.XViewerColumnLabelProvider; import org.eclipse.nebula.widgets.xviewer.XViewerColumnSorter; +import org.eclipse.nebula.widgets.xviewer.XViewerComputedColumn; import org.eclipse.nebula.widgets.xviewer.XViewerLabelProvider; import org.eclipse.nebula.widgets.xviewer.XViewerTreeReport; import org.eclipse.nebula.widgets.xviewer.util.internal.ArrayTreeContentProvider; @@ -87,7 +88,7 @@ public class XViewerCustomMenu { protected Action removeSelected; protected Action removeNonSelected; protected Action copySelected; - protected Action showColumn, hideColumn; + protected Action showColumn, addComputedColumn, hideColumn; protected Action copySelectedCell; protected Action viewSelectedCell; private Boolean headerMouseClick = false; @@ -132,6 +133,7 @@ public class XViewerCustomMenu { MenuManager mm = xViewer.getMenuManager(); mm.add(showColumn); mm.add(hideColumn); + mm.add(addComputedColumn); mm.add(copySelectedCell); mm.add(new Separator()); mm.add(filterByColumn); @@ -292,6 +294,43 @@ public class XViewerCustomMenu { } } + protected void handleAddComputedColumn() { + TreeColumn insertTreeCol = xViewer.getRightClickSelectedColumn(); + XViewerColumn insertXCol = (XViewerColumn) insertTreeCol.getData(); + XCheckFilteredTreeDialog dialog = + new XCheckFilteredTreeDialog("Add Computed Column", String.format("Column to compute against [%s]", + insertXCol.getName() + "(" + insertXCol.getId() + ")") + "\n\nSelect Columns to Add", patternFilter, + new ArrayTreeContentProvider(), new XViewerColumnLabelProvider(), new XViewerColumnSorter()); + Collection<XViewerComputedColumn> computedCols = xViewer.getComputedColumns(insertXCol); + if (computedCols.size() == 0) { + XViewerLib.popup("ERROR", "Selected column has no applicable computed columns"); + return; + } + dialog.setInput(computedCols); + if (dialog.open() == 0) { + // System.out.println("Selected " + dialog.getChecked()); + // System.out.println("Selected column to add before " + insertXCol); + CustomizeData custData = xViewer.getCustomizeMgr().generateCustDataFromTable(); + List<XViewerColumn> xCols = custData.getColumnData().getColumns(); + List<XViewerColumn> newXCols = new ArrayList<XViewerColumn>(); + for (XViewerColumn currXCol : xCols) { + if (currXCol.equals(insertXCol)) { + for (Object obj : dialog.getChecked()) { + XViewerComputedColumn newComputedXCol = ((XViewerComputedColumn) obj).copy(); + newComputedXCol.setShow(true); + newComputedXCol.setSourceXViewerColumn(insertXCol); + newComputedXCol.setXViewer(xViewer); + newXCols.add(newComputedXCol); + } + } + newXCols.add(currXCol); + } + custData.getColumnData().setColumns(newXCols); + xViewer.getCustomizeMgr().loadCustomization(custData); + xViewer.refresh(); + } + } + protected void handleHideColumn() { TreeColumn insertTreeCol = xViewer.getRightClickSelectedColumn(); XViewerColumn insertXCol = (XViewerColumn) insertTreeCol.getData(); @@ -317,6 +356,12 @@ public class XViewerCustomMenu { handleShowColumn(); }; }; + addComputedColumn = new Action("Add Computed Column") { + @Override + public void run() { + handleAddComputedColumn(); + }; + }; hideColumn = new Action("Hide Column") { @Override public void run() { diff --git a/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/util/internal/XViewerLib.java b/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/util/internal/XViewerLib.java index 97caa1c1e57..3ed67c17441 100644 --- a/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/util/internal/XViewerLib.java +++ b/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/util/internal/XViewerLib.java @@ -8,183 +8,190 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.nebula.widgets.xviewer.util.internal;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Random;
-import java.util.logging.Level;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.nebula.widgets.xviewer.Activator;
-import org.eclipse.nebula.widgets.xviewer.util.internal.images.XViewerImageCache;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * @author Donald G. Dunne
- */
-public class XViewerLib {
- static Random random = new Random();
-
- public static String generateGuidStr() {
- long rand = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) | 0x4000000000000000L;
- return Long.toString(rand, 32) + Long.toString(System.currentTimeMillis() & 0xFFFFFFFFFFFFFL, 32);
- }
-
- public static void writeStringToFile(String str, File outFile) throws IOException {
- OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8");
- char[] chars = str.toCharArray();
- out.write(chars, 0, chars.length);
- out.close();
- }
-
- public static void popup(final String title, final String message) {
- if (!PlatformUI.isWorkbenchRunning()) {
- XViewerLog.log(Activator.class, Level.SEVERE, message);
- } else {
- ensureInDisplayThread(new Runnable() {
- public void run() {
- MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title,
- message);
- }
- });
- }
- }
-
- public static GridLayout getZeroMarginLayout(int numColumns, boolean equalColumnWidth) {
- GridLayout layout = new GridLayout();
- layout.numColumns = numColumns;
- layout.makeColumnsEqualWidth = equalColumnWidth;
- layout.verticalSpacing = 0;
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- return layout;
- }
-
- public static GridLayout getZeroMarginLayout() {
- return getZeroMarginLayout(1, false);
- }
-
- public static ArrayList<String> readListFromDir(File directory, FilenameFilter filter, boolean keepExtension) {
- ArrayList<String> list = new ArrayList<String>(400);
-
- if (directory == null) {
- System.out.println("Invalid path: " + directory);
- return list;
- }
-
- File[] files = directory.listFiles(filter);
- if (files == null) {
- System.out.println("Invalid path: " + directory);
- return list;
- }
- if (files.length > 0) {
- Arrays.sort(files);
- }
-
- if (keepExtension) {
- for (int i = 0; i < files.length; i++) {
- list.add(files[i].getName());
- }
- } else {
- for (int i = 0; i < files.length; i++) {
- list.add(removeExtension(files[i].getName()));
- }
- }
-
- return list;
- }
-
- public static ArrayList<String> readListFromDir(String directory, FilenameFilter filter) {
- return readListFromDir(new File(directory), filter, false);
- }
-
- /**
- * Remove the file extension from the file path
- *
- * @param filepath
- * @return modified file path
- */
- public static String removeExtension(String filepath) {
- String ext = getExtension(filepath);
- if (ext != null && ext.length() > 0) {
- filepath = filepath.substring(0, filepath.length() - (ext.length() + 1));
- }
- return filepath;
- }
-
- /**
- * Determine is OS is windows
- *
- * @return <b>true</b> if OS is windows
- */
- public static boolean isWindows() {
- return System.getProperty("os.name").indexOf("indows") != -1;
- }
-
- /**
- * Get file extension from the file path
- *
- * @param filepath
- * @return file extension
- */
- public static String getExtension(String filepath) {
- filepath = filepath.trim();
- String separatorRegEx = File.separator;
- if (isWindows()) {
- separatorRegEx = "\\\\";
- }
- String[] pathsArray = filepath.split(separatorRegEx);
-
- String fileName = pathsArray[0];
- if (pathsArray.length > 0) {
- fileName = pathsArray[pathsArray.length - 1];
- }
-
- int index = fileName.lastIndexOf('.');
- if (index >= 0 && index + 1 < fileName.length()) {
- return fileName.substring(index + 1);
- } else {
- return "";
- }
- }
-
- public static void ensureInDisplayThread(Runnable runnable) {
- ensureInDisplayThread(runnable, false);
- }
-
- public static void ensureInDisplayThread(Runnable runnable, boolean forcePend) {
- if (isDisplayThread()) {
- // No need to check for force since this will always pend
- runnable.run();
- } else {
- if (forcePend) {
- Display.getDefault().syncExec(runnable);
- } else {
- Display.getDefault().asyncExec(runnable);
- }
- }
- }
-
- public static boolean isDisplayThread() {
- if (Display.getCurrent() == null) return false;
-
- return Display.getCurrent().getThread() == Thread.currentThread();
- }
-
- public static Image getImage(String imageName) {
- return XViewerImageCache.getImage(imageName);
- }
-
- public static ImageDescriptor getImageDescriptor(String imageName) {
- return XViewerImageCache.getImageDescriptor(imageName);
- }
-}
+package org.eclipse.nebula.widgets.xviewer.util.internal; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.Random; +import java.util.logging.Level; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.nebula.widgets.xviewer.Activator; +import org.eclipse.nebula.widgets.xviewer.util.internal.images.XViewerImageCache; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; + +/** + * @author Donald G. Dunne + */ +public class XViewerLib { + static Random random = new Random(); + private static final Date today = new Date(); + public static int MILLISECS_PER_DAY = (1000 * 60 * 60 * 24); + + public static long daysTillToday(Date date) { + return (date.getTime() - today.getTime()) / MILLISECS_PER_DAY; + } + + public static String generateGuidStr() { + long rand = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) | 0x4000000000000000L; + return Long.toString(rand, 32) + Long.toString(System.currentTimeMillis() & 0xFFFFFFFFFFFFFL, 32); + } + + public static void writeStringToFile(String str, File outFile) throws IOException { + OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"); + char[] chars = str.toCharArray(); + out.write(chars, 0, chars.length); + out.close(); + } + + public static void popup(final String title, final String message) { + if (!PlatformUI.isWorkbenchRunning()) { + XViewerLog.log(Activator.class, Level.SEVERE, message); + } else { + ensureInDisplayThread(new Runnable() { + public void run() { + MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, + message); + } + }); + } + } + + public static GridLayout getZeroMarginLayout(int numColumns, boolean equalColumnWidth) { + GridLayout layout = new GridLayout(); + layout.numColumns = numColumns; + layout.makeColumnsEqualWidth = equalColumnWidth; + layout.verticalSpacing = 0; + layout.marginWidth = 0; + layout.marginHeight = 0; + return layout; + } + + public static GridLayout getZeroMarginLayout() { + return getZeroMarginLayout(1, false); + } + + public static ArrayList<String> readListFromDir(File directory, FilenameFilter filter, boolean keepExtension) { + ArrayList<String> list = new ArrayList<String>(400); + + if (directory == null) { + System.out.println("Invalid path: " + directory); + return list; + } + + File[] files = directory.listFiles(filter); + if (files == null) { + System.out.println("Invalid path: " + directory); + return list; + } + if (files.length > 0) { + Arrays.sort(files); + } + + if (keepExtension) { + for (int i = 0; i < files.length; i++) { + list.add(files[i].getName()); + } + } else { + for (int i = 0; i < files.length; i++) { + list.add(removeExtension(files[i].getName())); + } + } + + return list; + } + + public static ArrayList<String> readListFromDir(String directory, FilenameFilter filter) { + return readListFromDir(new File(directory), filter, false); + } + + /** + * Remove the file extension from the file path + * + * @param filepath + * @return modified file path + */ + public static String removeExtension(String filepath) { + String ext = getExtension(filepath); + if (ext != null && ext.length() > 0) { + filepath = filepath.substring(0, filepath.length() - (ext.length() + 1)); + } + return filepath; + } + + /** + * Determine is OS is windows + * + * @return <b>true</b> if OS is windows + */ + public static boolean isWindows() { + return System.getProperty("os.name").indexOf("indows") != -1; + } + + /** + * Get file extension from the file path + * + * @param filepath + * @return file extension + */ + public static String getExtension(String filepath) { + filepath = filepath.trim(); + String separatorRegEx = File.separator; + if (isWindows()) { + separatorRegEx = "\\\\"; + } + String[] pathsArray = filepath.split(separatorRegEx); + + String fileName = pathsArray[0]; + if (pathsArray.length > 0) { + fileName = pathsArray[pathsArray.length - 1]; + } + + int index = fileName.lastIndexOf('.'); + if (index >= 0 && index + 1 < fileName.length()) { + return fileName.substring(index + 1); + } else { + return ""; + } + } + + public static void ensureInDisplayThread(Runnable runnable) { + ensureInDisplayThread(runnable, false); + } + + public static void ensureInDisplayThread(Runnable runnable, boolean forcePend) { + if (isDisplayThread()) { + // No need to check for force since this will always pend + runnable.run(); + } else { + if (forcePend) { + Display.getDefault().syncExec(runnable); + } else { + Display.getDefault().asyncExec(runnable); + } + } + } + + public static boolean isDisplayThread() { + if (Display.getCurrent() == null) return false; + + return Display.getCurrent().getThread() == Thread.currentThread(); + } + + public static Image getImage(String imageName) { + return XViewerImageCache.getImage(imageName); + } + + public static ImageDescriptor getImageDescriptor(String imageName) { + return XViewerImageCache.getImageDescriptor(imageName); + } +} diff --git a/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/AtsUtil.java b/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/AtsUtil.java index 539271ee9e5..e0ce9ed8870 100644 --- a/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/AtsUtil.java +++ b/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/AtsUtil.java @@ -15,6 +15,7 @@ import java.io.File; import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
@@ -84,11 +85,17 @@ public class AtsUtil implements IAtsLib { public static Color ACTIVE_COLOR = new Color(null, 206, 212, 241);
private static OseeGroup atsAdminGroup = null;
private static boolean goalEnabled = false;
+ private static final Date today = new Date();
+ public static int MILLISECS_PER_DAY = (1000 * 60 * 60 * 24);
public AtsUtil() {
super();
}
+ public long daysTillToday(Date date) throws OseeCoreException {
+ return (date.getTime() - today.getTime()) / MILLISECS_PER_DAY;
+ }
+
public static boolean isProductionDb() throws OseeCoreException {
return ClientSessionManager.isProductionDataStore();
}
diff --git a/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/SMAMetrics.java b/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/SMAMetrics.java index d9c47050df3..96de79bf801 100644 --- a/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/SMAMetrics.java +++ b/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/SMAMetrics.java @@ -34,8 +34,6 @@ import org.eclipse.osee.framework.ui.skynet.widgets.XDate; */
public class SMAMetrics {
- private static int MILLISECS_PER_DAY = (1000 * 60 * 60 * 24);
-
double estHours = 0;
double hrsRemainFromEstimates = 0;
double hrsSpent = 0;
@@ -65,8 +63,7 @@ public class SMAMetrics { this.manHoursPerDay = manHoursPerDay;
this.versionArtifact = versionArtifact;
this.estimatedReleaseDate = estimatedReleaseDate;
- if (artifacts.size() == 0)
- return;
+ if (artifacts.size() == 0) return;
for (Artifact art : artifacts) {
if (art instanceof ActionArtifact) {
actionArts.add((ActionArtifact) art);
@@ -110,8 +107,7 @@ public class SMAMetrics { manDaysNeeded += team.getWorldViewManDaysNeeded();
cummulativeWorkflowPercentComplete += team.getWorldViewPercentCompleteTotal();
}
- if (hrsRemainFromEstimates != 0)
- manDaysNeeded = hrsRemainFromEstimates / manHoursPerDay;
+ if (hrsRemainFromEstimates != 0) manDaysNeeded = hrsRemainFromEstimates / manHoursPerDay;
percentCompleteByWorkflowPercents = 0;
if (getNumSMAs() > 0 && cummulativeWorkflowPercentComplete > 0) {
percentCompleteByWorkflowPercents = cummulativeWorkflowPercentComplete / getNumSMAs();
@@ -123,7 +119,7 @@ public class SMAMetrics { estimatedReleaseDate = versionArtifact.getEstimatedReleaseDate();
}
if (estimatedReleaseDate != null && estimatedReleaseDate.after(today)) {
- daysTillRel = (estimatedReleaseDate.getTime() - today.getTime()) / MILLISECS_PER_DAY;
+ daysTillRel = (estimatedReleaseDate.getTime() - today.getTime()) / AtsUtil.MILLISECS_PER_DAY;
}
str =
String.format("TeamWFs: %s Tasks: %s EstHrs: %5.2f %sCmp: %5.2f RmnHrs: %5.2f HrsSpnt: %5.2f %s %s",
@@ -148,8 +144,7 @@ public class SMAMetrics { @SuppressWarnings("unchecked")
public <A extends StateMachineArtifact> Collection<A> getUserToCompletedSmas(User user, Class<A> clazz) {
- if (!userToCompletedSmas.containsKey(user))
- return Collections.emptyList();
+ if (!userToCompletedSmas.containsKey(user)) return Collections.emptyList();
List<A> smas = new ArrayList<A>();
for (Artifact art : userToCompletedSmas.getValues(user)) {
if (clazz == null || art.getClass().isInstance(clazz)) {
@@ -161,8 +156,7 @@ public class SMAMetrics { @SuppressWarnings("unchecked")
public <A extends StateMachineArtifact> Collection<A> getUserToAssignedSmas(User user, Class<A> clazz) {
- if (!userToAssignedSmas.containsKey(user))
- return Collections.emptyList();
+ if (!userToAssignedSmas.containsKey(user)) return Collections.emptyList();
List<A> smas = new ArrayList<A>();
for (Artifact art : userToAssignedSmas.getValues(user)) {
if (clazz == null || art.getClass().equals(clazz)) {
@@ -193,20 +187,16 @@ public class SMAMetrics { }
public double getPercentCompleteByTeamWorkflow() throws OseeCoreException {
- if (getTeamArts().size() == 0)
- return 0;
+ if (getTeamArts().size() == 0) return 0;
double completed = getCompletedTeamWorkflows().size();
- if (completed == 0)
- return 0;
+ if (completed == 0) return 0;
return completed / getTeamArts().size() * 100;
}
public double getPercentCompleteByWorkflow() throws OseeCoreException {
- if (smas.size() == 0)
- return 0;
+ if (smas.size() == 0) return 0;
double completed = getCompletedWorkflows().size();
- if (completed == 0)
- return 0;
+ if (completed == 0) return 0;
return completed / smas.size() * 100;
}
@@ -221,11 +211,9 @@ public class SMAMetrics { }
public double getPercentCompleteByTaskWorkflow() throws OseeCoreException {
- if (getTaskArts().size() == 0)
- return 0;
+ if (getTaskArts().size() == 0) return 0;
double completed = getCompletedTaskWorkflows().size();
- if (completed == 0)
- return 0;
+ if (completed == 0) return 0;
return completed / getTaskArts().size() * 100;
}
@@ -338,8 +326,7 @@ public class SMAMetrics { public int getNumNotEstimated() throws OseeCoreException {
int count = 0;
for (StateMachineArtifact sma : smas) {
- if (sma.getWorldViewEstimatedHours() == 0)
- count++;
+ if (sma.getWorldViewEstimatedHours() == 0) count++;
}
return count;
}
|