Enhance default suite dashboard
authorbsinou <bsinou@argeo.org>
Sat, 8 Apr 2017 09:03:33 +0000 (11:03 +0200)
committerbsinou <bsinou@argeo.org>
Sat, 8 Apr 2017 09:03:33 +0000 (11:03 +0200)
org.argeo.suite.workbench.rap/META-INF/spring/osgi.xml
org.argeo.suite.workbench.rap/META-INF/spring/parts.xml
org.argeo.suite.workbench.rap/src/org/argeo/suite/workbench/parts/AbstractSuiteDashboard.java
org.argeo.suite.workbench.rap/src/org/argeo/suite/workbench/parts/DefaultDashboardEditor.java
pom.xml

index 330d40ee3ab2c7d900e7d145d7c14c9dc88de17b..4dd9d0ca2a6ca132825a8fbf7435d730d572673e 100644 (file)
@@ -15,6 +15,7 @@
        <reference id="documentsService" interface="org.argeo.documents.DocumentsService" />\r
        <reference id="trackerService" interface="org.argeo.tracker.TrackerService" />\r
 \r
+       <reference id="systemAppService" interface="org.argeo.connect.SystemAppService" />\r
        <reference id="systemWorkbenchService"\r
                interface="org.argeo.connect.workbench.SystemWorkbenchService" />\r
 \r
index 01f6a5107d5767b2fd665c8655051ea925c5ec73..9bf6e6aec08fa505817688d4b1953cfa7cd866c3 100644 (file)
@@ -23,6 +23,7 @@
                <property name="activitiesService" ref="activitiesService" />
                <property name="trackerService" ref="trackerService" />
                <!-- <property name="documentsService" ref="documentsService" /> -->
+               <property name="systemAppService" ref="systemAppService" />
                <property name="systemWorkbenchService" ref="systemWorkbenchService" />
        </bean>
 </beans>
index 6ca460eb55be19fbdb930c520cad702195de9317..7e0c4a6613924c86bde3933bee283021d54f4b64 100644 (file)
@@ -23,7 +23,6 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
@@ -47,7 +46,6 @@ public abstract class AbstractSuiteDashboard extends EditorPart {
        private Session session;
 
        // UI Objects
-       private Image logoImg;
        private FormToolkit toolkit;
 
        @Override
@@ -56,7 +54,6 @@ public abstract class AbstractSuiteDashboard extends EditorPart {
                setInput(input);
 
                session = ConnectJcrUtils.login(repository);
-               // initialiseImg();
                updateTooltip(input);
        }
 
@@ -67,26 +64,6 @@ public abstract class AbstractSuiteDashboard extends EditorPart {
                }
        }
 
-       // private void initialiseImg() {
-       // InputStream is = null;
-       // try {
-       // String imgPath = peopleService.getInstanceConfPath() + "/"
-       // + AoNames.AO_DEFAULT_LOGO;
-       // if (session.nodeExists(imgPath)) {
-       // Node imageNode = session.getNode(imgPath).getNode(
-       // Node.JCR_CONTENT);
-       // is = imageNode.getProperty(Property.JCR_DATA).getBinary()
-       // .getStream();
-       // logoImg = new Image(this.getSite().getShell().getDisplay(), is);
-       // }
-       // } catch (RepositoryException re) {
-       // throw new AoException(
-       // "Unable to initialise specific logo for demo app", re);
-       // } finally {
-       // IOUtils.closeQuietly(is);
-       // }
-       // }
-
        /**
         * Implementing classes must call super in order to create the correct form
         * toolkit
@@ -150,8 +127,6 @@ public abstract class AbstractSuiteDashboard extends EditorPart {
        @Override
        public void dispose() {
                JcrUtils.logoutQuietly(session);
-               if (logoImg != null)
-                       logoImg.dispose();
                super.dispose();
        }
 
index d879d7e54c2017af63c0aaba321921b409dc0938..eb7c569301726da948b6192c59d0e6ae3c4eff9a 100644 (file)
@@ -18,6 +18,7 @@ import org.argeo.cms.auth.CurrentUser;
 import org.argeo.cms.ui.workbench.util.CommandUtils;
 import org.argeo.cms.util.CmsUtils;
 import org.argeo.connect.ConnectNames;
+import org.argeo.connect.ui.ConnectUiUtils;
 import org.argeo.connect.util.ConnectJcrUtils;
 import org.argeo.connect.workbench.Refreshable;
 import org.argeo.connect.workbench.commands.OpenEntityEditor;
@@ -28,6 +29,7 @@ import org.argeo.suite.SuiteException;
 import org.argeo.suite.workbench.AsUiPlugin;
 import org.argeo.tracker.TrackerNames;
 import org.argeo.tracker.TrackerService;
+import org.argeo.tracker.TrackerTypes;
 import org.argeo.tracker.core.TrackerUtils;
 import org.argeo.tracker.ui.TaskListLabelProvider;
 import org.argeo.tracker.ui.TaskVirtualListComposite;
@@ -67,41 +69,73 @@ public class DefaultDashboardEditor extends AbstractSuiteDashboard implements Re
                bodyCmp.setLayoutData(EclipseUiUtils.fillAll());
                bodyCmp.setLayout(new GridLayout());
 
-               // Header
-               try {
-                       headerCmp = createHeaderPart(bodyCmp, NodeUtils.getUserHome(getSession()));
-                       headerCmp.setLayoutData(EclipseUiUtils.fillWidth());
-
-               } catch (RepositoryException e) {
-                       throw new SuiteException("Cannot create dashboard overview", e);
-               }
+               headerCmp = new Composite(bodyCmp, SWT.NO_FOCUS);
+               headerCmp.setLayoutData(EclipseUiUtils.fillWidth());
 
                taskListCmp = new Composite(bodyCmp, SWT.NO_FOCUS);
                taskListCmp.setLayoutData(EclipseUiUtils.fillAll());
-
-               populateTaskListCmp();
+               forceRefresh(null);
        }
 
-       private void populateTaskListCmp() {
+       @Override
+       public void forceRefresh(Object object) {
+               CmsUtils.clear(headerCmp);
+               populateHeaderPart(headerCmp, NodeUtils.getUserHome(getSession()));
+
                CmsUtils.clear(taskListCmp);
-               taskListCmp.setLayout(EclipseUiUtils.noSpaceGridLayout());
-               // Composite innerCmp = new Composite(taskListCmp, SWT.NO_FOCUS);
-               // innerCmp.setLayoutData(EclipseUiUtils.fillAll());
+               populateTaskListCmp(taskListCmp);
 
-               TaskListLabelProvider labelProvider = new TaskListLabelProvider(trackerService);
-               tvlc = new TaskVirtualListComposite(taskListCmp, SWT.NO_FOCUS, labelProvider, 54);
-               tvlc.setLayoutData(EclipseUiUtils.fillAll());
-               forceRefresh(null);
+               headerCmp.getParent().layout(true, true);
        }
 
-       @Override
-       public void forceRefresh(Object object) {
+       private void populateTaskListCmp(Composite parent) {
+               parent.setLayout(EclipseUiUtils.noSpaceGridLayout());
                NodeIterator nit = activitiesService.getMyTasks(getSession(), true);
-               tvlc.getTableViewer().setInput(JcrUtils.nodeIteratorToList(nit).toArray());
+               if (!nit.hasNext()) {
+                       Composite noTaskCmp = new Composite(parent, SWT.NO_FOCUS);
+                       noTaskCmp.setLayoutData(EclipseUiUtils.fillAll());
+                       noTaskCmp.setLayout(new GridLayout());
+
+                       Label noTaskLbl = new Label(noTaskCmp, SWT.CENTER);
+                       noTaskLbl.setText("<i> <big> You have no pending Task. </big> </i>");
+                       CmsUtils.markup(noTaskLbl);
+                       noTaskLbl.setLayoutData(new GridData(SWT.CENTER, SWT.BOTTOM, true, true));
+
+                       final Link createTaskLk = new Link(noTaskCmp, SWT.CENTER);
+                       createTaskLk.setText("<a> Create a task </a>");
+                       createTaskLk.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, true));
+
+                       createTaskLk.addSelectionListener(new SelectionAdapter() {
+                               private static final long serialVersionUID = -9028457805156989935L;
+
+                               @Override
+                               public void widgetSelected(SelectionEvent e) {
+                                       String mainMixin = TrackerTypes.TRACKER_TASK;
+                                       String pathCreated = ConnectUiUtils.createAndConfigureEntity(createTaskLk.getShell(), getSession(),
+                                                       getSystemAppService(), getSystemWorkbenchService(), mainMixin);
+                                       if (EclipseUiUtils.notEmpty(pathCreated))
+                                               forceRefresh(null);
+                               }
+                       });
+
+               } else {
+                       TaskListLabelProvider labelProvider = new TaskListLabelProvider(trackerService);
+                       tvlc = new TaskVirtualListComposite(parent, SWT.NO_FOCUS, labelProvider, 54);
+                       tvlc.setLayoutData(EclipseUiUtils.fillAll());
+                       tvlc.getTableViewer().setInput(JcrUtils.nodeIteratorToList(nit).toArray());
+               }
        }
 
-       private Composite createHeaderPart(Composite parent, Node context) throws RepositoryException {
-               Composite bodyCmp = new Composite(parent, SWT.NO_FOCUS);
+       private boolean isOverdue(Node node, String propName) {
+               try {
+                       Calendar now = GregorianCalendar.getInstance();
+                       return node.hasProperty(propName) && node.getProperty(propName).getDate().before(now);
+               } catch (RepositoryException e) {
+                       throw new SuiteException("Cannot check overdue status with property " + propName + " on " + node, e);
+               }
+       }
+
+       private void populateHeaderPart(Composite bodyCmp, Node context) {
                bodyCmp.setLayout(EclipseUiUtils.noSpaceGridLayout(new GridLayout(2, true)));
 
                Composite leftCmp = new Composite(bodyCmp, SWT.NO_FOCUS);
@@ -121,15 +155,12 @@ public class DefaultDashboardEditor extends AbstractSuiteDashboard implements Re
                gd.horizontalIndent = 10;
                titleLbl.setLayoutData(gd);
 
-               Calendar now = GregorianCalendar.getInstance();
-
                NodeIterator nit = activitiesService.getMyTasks(getSession(), true);
                if (nit.hasNext()) {
                        List<Node> overdueTasks = new ArrayList<>();
                        while (nit.hasNext()) {
                                Node currNode = nit.nextNode();
-                               if (currNode.hasProperty(ActivitiesNames.ACTIVITIES_DUE_DATE)
-                                               && currNode.getProperty(ActivitiesNames.ACTIVITIES_DUE_DATE).getDate().before(now))
+                               if (isOverdue(currNode, ActivitiesNames.ACTIVITIES_DUE_DATE))
                                        overdueTasks.add(currNode);
                        }
                        if (!overdueTasks.isEmpty()) {
@@ -148,8 +179,7 @@ public class DefaultDashboardEditor extends AbstractSuiteDashboard implements Re
                        while (nit.hasNext()) {
                                Node currNode = nit.nextNode();
                                openMilestones.add(currNode);
-                               if (currNode.hasProperty(TrackerNames.TRACKER_TARGET_DATE)
-                                               && currNode.getProperty(TrackerNames.TRACKER_TARGET_DATE).getDate().before(now))
+                               if (isOverdue(currNode, TrackerNames.TRACKER_TARGET_DATE))
                                        overdueMilestones.add(currNode);
                        }
                        if (!overdueMilestones.isEmpty()) {
@@ -177,7 +207,6 @@ public class DefaultDashboardEditor extends AbstractSuiteDashboard implements Re
                        myMilestoneGp.setLayoutData(EclipseUiUtils.fillWidth());
                        populateMuliValueClickableList(myMilestoneGp, openMilestones.toArray(new Node[0]), new MilestoneLp(), null);
                }
-               return bodyCmp;
        }
 
        private class ProjectLp extends ColumnLabelProvider {
@@ -197,7 +226,8 @@ public class DefaultDashboardEditor extends AbstractSuiteDashboard implements Re
                        if (allNb < 1)
                                percent = "empty";
                        else {
-                               double result = (allNb - openNb) / allNb * 100;
+                               double num = allNb - openNb;
+                               double result = num / allNb * 100;
                                percent = String.format("%.1f", result) + "% done";
                        }
                        StringBuilder builder = new StringBuilder();
@@ -230,7 +260,8 @@ public class DefaultDashboardEditor extends AbstractSuiteDashboard implements Re
                        if (allNb < 1)
                                percent = "empty";
                        else {
-                               double result = (allNb - openNb) / allNb * 100;
+                               double num = allNb - openNb;
+                               double result = num / allNb * 100;
                                percent = String.format("%.1f", result) + "% done";
                        }
                        StringBuilder builder = new StringBuilder();
@@ -296,7 +327,7 @@ public class DefaultDashboardEditor extends AbstractSuiteDashboard implements Re
        private void populateMuliValueClickableList(Composite parent, Node[] nodes, ColumnLabelProvider lp,
                        String listLabel) {
                CmsUtils.clear(parent);
-               RowLayout rl = new RowLayout(SWT.HORIZONTAL);
+               RowLayout rl = new RowLayout(SWT.HORIZONTAL | SWT.WRAP);
                rl.wrap = true;
                rl.marginLeft = rl.marginTop = rl.marginBottom = 0;
                rl.marginRight = 8;
@@ -314,9 +345,9 @@ public class DefaultDashboardEditor extends AbstractSuiteDashboard implements Re
                        CmsUtils.markup(link);
                        link.setText(lp.getText(node) + (i != nodes.length ? ", " : ""));
                        i++;
-//                     Color fc = lp.getForeground(node);
-//                     if (fc != null)
-//                             link.setForeground(fc);
+                       // Color fc = lp.getForeground(node);
+                       // if (fc != null)
+                       // link.setForeground(fc);
 
                        link.addSelectionListener(new SelectionAdapter() {
                                private static final long serialVersionUID = 1L;
diff --git a/pom.xml b/pom.xml
index c35dc6d86d801b5748c0f5f1e79c6858329f5ff9..a05fc58e1ea11d3dc2026a2c22f92eedd9bc024d 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
        <parent>
                <groupId>org.argeo.commons</groupId>
                <artifactId>argeo-commons</artifactId>
-               <version>2.1.67</version>
+               <version>2.1.68-SNAPSHOT</version>
        </parent>
        <groupId>org.argeo.suite</groupId>
        <artifactId>argeo-suite</artifactId>