Source Code Cross Referenced for TakeOutline.java in  » Rule-Engine » take » nz » ac » massey » take » takeep » outline » 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 » Rule Engine » take » nz.ac.massey.take.takeep.outline 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package nz.ac.massey.take.takeep.outline;
002:
003:        import java.net.URL;
004:        import java.util.HashMap;
005:        import java.util.LinkedList;
006:        import java.util.StringTokenizer;
007:
008:        import nz.ac.massey.take.takeep.Activator;
009:        import nz.ac.massey.take.takeep.editor.TakeEditor;
010:        import nz.ac.massey.take.takeep.editor.tokens.TakePartitionScanner.TAKE_PARTITIONS;
011:
012:        import org.eclipse.jface.resource.ImageDescriptor;
013:        import org.eclipse.jface.text.BadLocationException;
014:        import org.eclipse.jface.text.IDocument;
015:        import org.eclipse.jface.text.ITypedRegion;
016:        import org.eclipse.jface.text.source.IAnnotationModel;
017:        import org.eclipse.jface.viewers.ISelection;
018:        import org.eclipse.jface.viewers.IStructuredSelection;
019:        import org.eclipse.jface.viewers.ITreeContentProvider;
020:        import org.eclipse.jface.viewers.LabelProvider;
021:        import org.eclipse.jface.viewers.SelectionChangedEvent;
022:        import org.eclipse.jface.viewers.TreeViewer;
023:        import org.eclipse.jface.viewers.Viewer;
024:        import org.eclipse.swt.graphics.Image;
025:        import org.eclipse.swt.widgets.Composite;
026:        import org.eclipse.swt.widgets.Control;
027:        import org.eclipse.ui.IEditorInput;
028:        import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
029:
030:        public class TakeOutline extends ContentOutlinePage {
031:            private TakeEditor editor;
032:            private IEditorInput fInput;
033:
034:            public TakeOutline(TakeEditor takeEditor) {
035:                this .editor = takeEditor;
036:
037:                if (this .editor.getEditorInput() != null)
038:                    this .fInput = this .editor.getEditorInput();
039:            }
040:
041:            @Override
042:            public void createControl(Composite parent) {
043:
044:                super .createControl(parent);
045:
046:                TreeViewer viewer = getTreeViewer();
047:
048:                TreeHugger treeHugger = new TreeHugger();
049:                viewer.setContentProvider(treeHugger);
050:                viewer.setLabelProvider(new TakeOutlineLabelProvider());
051:                viewer.addSelectionChangedListener(this );
052:                if (this .fInput != null)
053:                    viewer.setInput(this .fInput);
054:
055:            }
056:
057:            @Override
058:            public void selectionChanged(SelectionChangedEvent event) {
059:
060:                super .selectionChanged(event);
061:
062:                ISelection selection = event.getSelection();
063:                if (selection.isEmpty())
064:                    this .editor.resetHighlightRange();
065:                else {
066:
067:                    Object object = (((IStructuredSelection) selection)
068:                            .getFirstElement());
069:                    if (object instanceof  ITypedRegion) {
070:
071:                        ITypedRegion it = (ITypedRegion) object;
072:                        try {
073:                            this .editor.setHighlightRange(it.getOffset(), it
074:                                    .getLength(), true);
075:                        } catch (IllegalArgumentException x) {
076:                            this .editor.resetHighlightRange();
077:                        }
078:                    }
079:
080:                }
081:            }
082:
083:            private class TakeOutlineLabelProvider extends LabelProvider {
084:
085:                private int maxlength = 35;
086:                private HashMap<String, Image> images = new HashMap<String, Image>();
087:
088:                @Override
089:                public Image getImage(Object element) {
090:                    if (element instanceof  ITypedRegion) {
091:                        ITypedRegion region = (ITypedRegion) element;
092:
093:                        if (!this .images.containsKey(region.getType())) {
094:                            Image img = null;
095:                            URL url = null;
096:                            if (region.getType() == TAKE_PARTITIONS.TAKE_LOCAL_ANNOTATION
097:                                    .name()) {
098:                                url = Activator
099:                                        .getDefault()
100:                                        .getBundle()
101:                                        .getEntry(
102:                                                "/icons/partitions/localannotation.gif");
103:
104:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_GLOBAL_ANNOTATION
105:                                    .name()) {
106:                                url = Activator
107:                                        .getDefault()
108:                                        .getBundle()
109:                                        .getEntry(
110:                                                "/icons/partitions/globalannotation.gif");
111:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_COMMENT
112:                                    .name()) {
113:                                url = Activator
114:                                        .getDefault()
115:                                        .getBundle()
116:                                        .getEntry(
117:                                                "/icons/partitions/comment.gif");
118:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_RULE_OR_FACT
119:                                    .name()) {
120:                                url = Activator.getDefault().getBundle()
121:                                        .getEntry("/icons/partitions/rule.gif");
122:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_VAR
123:                                    .name()) {
124:                                url = Activator.getDefault().getBundle()
125:                                        .getEntry("/icons/partitions/var.gif");
126:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_QUERY
127:                                    .name()) {
128:                                url = Activator
129:                                        .getDefault()
130:                                        .getBundle()
131:                                        .getEntry("/icons/partitions/query.gif");
132:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_EXTERNAL
133:                                    .name()) {
134:                                url = Activator
135:                                        .getDefault()
136:                                        .getBundle()
137:                                        .getEntry(
138:                                                "/icons/partitions/external.gif");
139:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_REF
140:                                    .name()) {
141:                                url = Activator
142:                                        .getDefault()
143:                                        .getBundle()
144:                                        .getEntry(
145:                                                "/icons/partitions/reference.gif");
146:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_AGGREGATION
147:                                    .name()) {
148:                                url = Activator.getDefault().getBundle()
149:                                        .getEntry("/icons/partitions/agg.gif");
150:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_IMPORT
151:                                    .name()) {
152:                                url = Activator.getDefault().getBundle()
153:                                        .getEntry(
154:                                                "/icons/partitions/import.gif");
155:                            }
156:                            if (url != null) {
157:                                img = ImageDescriptor.createFromURL(url)
158:                                        .createImage();
159:                                this .images.put(region.getType(), img);
160:                            } else {
161:                                System.out.println("No image for "
162:                                        + region.getType());
163:                                this .images.put(region.getType(), null);
164:                            }
165:                        }
166:
167:                        return this .images.get(region.getType());
168:
169:                    }
170:                    return null;
171:                }
172:
173:                @Override
174:                public String getText(Object element) {
175:                    if (element instanceof  ITypedRegion
176:                            && getTreeViewer() instanceof  TreeViewer) {
177:                        ITypedRegion region = (ITypedRegion) element;
178:                        try {
179:
180:                            Object root = ((ITreeContentProvider) (getTreeViewer())
181:                                    .getContentProvider()).getParent(element);
182:                            IDocument document = TakeOutline.this .editor
183:                                    .getDocumentProvider().getDocument(root);
184:
185:                            String line = document.get(region.getOffset(),
186:                                    region.getLength());
187:
188:                            line = line.trim();
189:
190:                            String processedLine = null;
191:
192:                            if (region.getType() == TAKE_PARTITIONS.TAKE_AGGREGATION
193:                                    .name()
194:                                    || region.getType() == TAKE_PARTITIONS.TAKE_IMPORT
195:                                            .name()) {
196:                                // TAKE 2nd item
197:                                StringTokenizer st = new StringTokenizer(line,
198:                                        " ");
199:                                st.nextToken();
200:                                processedLine = st.nextToken();
201:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_REF
202:                                    .name()
203:                                    || region.getType() == TAKE_PARTITIONS.TAKE_VAR
204:                                            .name()) {
205:                                // TAKE 3rd item
206:                                StringTokenizer st = new StringTokenizer(line,
207:                                        " ");
208:                                st.nextToken();
209:                                st.nextToken();
210:                                processedLine = st.nextToken();
211:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_COMMENT
212:                                    .name()) {
213:
214:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_EXTERNAL
215:                                    .name()) {
216:                                StringTokenizer st = new StringTokenizer(line,
217:                                        " ");
218:                                st.nextToken();
219:                                processedLine = st.nextToken();
220:                                if (processedLine.endsWith(":")) {
221:                                    processedLine = processedLine.substring(0,
222:                                            processedLine.length() - 1);
223:                                }
224:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_GLOBAL_ANNOTATION
225:                                    .name()
226:                                    || region.getType() == TAKE_PARTITIONS.TAKE_LOCAL_ANNOTATION
227:                                            .name()) {
228:                                StringTokenizer st = new StringTokenizer(line,
229:                                        "=");
230:                                processedLine = st.nextToken();
231:                                processedLine = processedLine.replaceAll("@",
232:                                        "");
233:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_QUERY
234:                                    .name()) {
235:                                StringTokenizer st = new StringTokenizer(line,
236:                                        " [");
237:                                st.nextToken();
238:                                processedLine = st.nextToken();
239:                            } else if (region.getType() == TAKE_PARTITIONS.TAKE_RULE_OR_FACT
240:                                    .name()) {
241:                                StringTokenizer st = new StringTokenizer(line,
242:                                        ":");
243:
244:                                processedLine = st.nextToken();
245:                            }
246:
247:                            if (processedLine == null) {
248:                                processedLine = line;
249:                            }
250:
251:                            if (processedLine.length() > this .maxlength) {
252:                                processedLine = processedLine.substring(0,
253:                                        this .maxlength - 2);
254:                                processedLine += "..";
255:                            }
256:
257:                            return processedLine;
258:                        } catch (Exception e) {
259:
260:                            e.printStackTrace();
261:                        }
262:
263:                    }
264:                    return element.toString();
265:                }
266:
267:                @Override
268:                public void dispose() {
269:
270:                    for (Image i : this .images.values()) {
271:                        if (i != null) {
272:                            i.dispose();
273:                        }
274:                    }
275:                    super .dispose();
276:                }
277:
278:            }
279:
280:            private class TreeHugger implements  ITreeContentProvider {
281:
282:                private TreeViewer viewer;
283:                private Object root;
284:                private LinkedList<Object> regions = new LinkedList<Object>();
285:
286:                @Override
287:                public void dispose() {
288:                    // TODO Auto-generated method stub
289:
290:                }
291:
292:                @Override
293:                public void inputChanged(Viewer viewer, Object oldInput,
294:                        Object newInput) {
295:                    if (viewer instanceof  TreeViewer) {
296:                        this .viewer = (TreeViewer) viewer;
297:                    }
298:
299:                    if (newInput != null) {
300:                        IDocument document = TakeOutline.this .editor
301:                                .getDocumentProvider().getDocument(newInput);
302:
303:                        this .root = newInput;
304:                        parse(document);
305:                        this .viewer.getTree().setItemCount(this .regions.size());
306:                    }
307:                }
308:
309:                private void parse(IDocument document) {
310:                    this .regions.clear();
311:                    try {
312:
313:                        ITypedRegion[] re = document.computePartitioning(0,
314:                                document.getLength());
315:
316:                        for (ITypedRegion ty : re) {
317:                            if (ty.getType() == IDocument.DEFAULT_CONTENT_TYPE) {
318:
319:                                continue;
320:                            }
321:                            this .regions.add(ty);
322:                        }
323:
324:                    } catch (BadLocationException e) {
325:                        // TODO Auto-generated catch block
326:                        e.printStackTrace();
327:                    }
328:
329:                }
330:
331:                @Override
332:                public Object[] getChildren(Object parentElement) {
333:                    if (parentElement == this .root) {
334:                        return this .regions.toArray();
335:                    }
336:
337:                    return new Object[0];
338:
339:                }
340:
341:                public Object getParent(Object element) {
342:
343:                    return this .root;
344:                }
345:
346:                @Override
347:                public boolean hasChildren(Object element) {
348:                    if (element == this .root) {
349:                        return true;
350:                    }
351:                    return false;
352:                }
353:
354:                @Override
355:                public Object[] getElements(Object inputElement) {
356:
357:                    if (inputElement == this .root) {
358:                        return this .regions.toArray();
359:                    }
360:                    return new Object[0];
361:                }
362:
363:            }
364:
365:            public void update() {
366:                TreeViewer viewer = getTreeViewer();
367:                if (viewer != null) {
368:                    Control control = viewer.getControl();
369:                    if (control != null && !control.isDisposed()) {
370:                        control.setRedraw(false);
371:                        viewer.setInput(this .editor.getEditorInput());
372:                        control.setRedraw(true);
373:                    }
374:                }
375:            }
376:
377:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.