Source Code Cross Referenced for SuccesorTaskFinder.java in  » IDE-Eclipse » ui » org » eclipse » ui » internal » cheatsheets » composite » model » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » ui » org.eclipse.ui.internal.cheatsheets.composite.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal.cheatsheets.composite.model;
011:
012:        import java.util.ArrayList;
013:        import java.util.List;
014:
015:        import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask;
016:        import org.eclipse.ui.internal.provisional.cheatsheets.ITaskGroup;
017:
018:        public class SuccesorTaskFinder {
019:
020:            private AbstractTask currentTask;
021:            ICompositeCheatSheetTask bestLaterTask;
022:            ICompositeCheatSheetTask bestEarlierTask;
023:            private boolean seenThisTask;
024:
025:            public SuccesorTaskFinder(ICompositeCheatSheetTask task) {
026:                currentTask = (AbstractTask) task;
027:            }
028:
029:            /**
030:             * Find the next recommended task or tasks to be completed.
031:             * Algorithm - visualize the tree as having its root at the top,
032:             * children below and to the left of their parents and then
033:             * search the tree from left to right. Look for 
034:             * the best predecessor which is the first task to the
035:             * left of this task that is runnable and the best successor 
036:             * which is the first task to the
037:             * right of this task which is runnable. 
038:             * @param task The task which was just completed
039:             * @return An array of tasks which can be started
040:             */
041:            public ICompositeCheatSheetTask[] getRecommendedSuccessors() {
042:                // TODO this code could be moved to TaskGroup
043:                if (ITaskGroup.CHOICE.equals(currentTask.getKind())) {
044:                    // For a choice if more than one child is runnable return it
045:                    List runnableChoices = findRunnableChoices();
046:                    if (runnableChoices.size() != 0) {
047:                        return (ICompositeCheatSheetTask[]) runnableChoices
048:                                .toArray(new ICompositeCheatSheetTask[runnableChoices
049:                                        .size()]);
050:                    }
051:                }
052:                return getBestSuccessor();
053:            }
054:
055:            private List findRunnableChoices() {
056:                List result;
057:                result = new ArrayList();
058:                if (isStartable(currentTask)) {
059:                    ICompositeCheatSheetTask[] subtasks = currentTask
060:                            .getSubtasks();
061:                    for (int i = 0; i < subtasks.length; i++) {
062:                        if (isStartable(subtasks[i])) {
063:                            result.add(subtasks[i]);
064:                        }
065:                    }
066:                }
067:                return result;
068:            }
069:
070:            private boolean isStartable(ICompositeCheatSheetTask task) {
071:                int state = task.getState();
072:                return (state != ICompositeCheatSheetTask.COMPLETED
073:                        && state != ICompositeCheatSheetTask.SKIPPED && task
074:                        .requiredTasksCompleted());
075:            }
076:
077:            private ICompositeCheatSheetTask[] getBestSuccessor() {
078:                bestLaterTask = null;
079:                bestEarlierTask = null;
080:                seenThisTask = false;
081:                searchRunnableChildren(currentTask.getCompositeCheatSheet()
082:                        .getRootTask());
083:                // If there is a task which is found later in the tree return
084:                // that, otherwise an earlier task.
085:                if (bestLaterTask != null) {
086:                    return new ICompositeCheatSheetTask[] { bestLaterTask };
087:                }
088:                if (bestEarlierTask != null) {
089:                    return new ICompositeCheatSheetTask[] { bestEarlierTask };
090:                }
091:                return new ICompositeCheatSheetTask[0];
092:            }
093:
094:            private void searchRunnableChildren(ICompositeCheatSheetTask task) {
095:                // Don't search completed tasks or their children
096:                // and stop searching if we've already found the best successor
097:                if (bestLaterTask != null) {
098:                    return;
099:                }
100:                if (task == currentTask) {
101:                    seenThisTask = true;
102:                }
103:                if (task.getState() == ICompositeCheatSheetTask.COMPLETED
104:                        || task.getState() == ICompositeCheatSheetTask.SKIPPED) {
105:                    if (isTaskAncestor(task, currentTask)) {
106:                        seenThisTask = true;
107:                    }
108:                    return;
109:                }
110:
111:                if (isStartable(task) && task != currentTask) {
112:                    if (seenThisTask) {
113:                        if (bestLaterTask == null) {
114:                            bestLaterTask = task;
115:                        }
116:                    } else {
117:                        if (bestEarlierTask == null) {
118:                            bestEarlierTask = task;
119:                        }
120:                    }
121:                }
122:
123:                ICompositeCheatSheetTask[] subtasks = task.getSubtasks();
124:                for (int i = 0; i < subtasks.length; i++) {
125:                    searchRunnableChildren(subtasks[i]);
126:                }
127:
128:            }
129:
130:            private boolean isTaskAncestor(
131:                    ICompositeCheatSheetTask ancestorCandididate,
132:                    ICompositeCheatSheetTask task) {
133:                ICompositeCheatSheetTask nextTask = task;
134:                while (nextTask != null) {
135:                    if (nextTask == ancestorCandididate) {
136:                        return true;
137:                    }
138:                    nextTask = nextTask.getParent();
139:                }
140:                return false;
141:            }
142:        }
w_w___w_._ja__v___a2_s_.com_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.