Source Code Cross Referenced for CoreItem.java in  » IDE-Eclipse » ui » org » eclipse » ui » internal » cheatsheets » views » 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.views 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2002, 2007 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.views;
011:
012:        import java.util.ArrayList;
013:        import java.util.Iterator;
014:        import java.util.StringTokenizer;
015:
016:        import org.eclipse.core.runtime.IStatus;
017:        import org.eclipse.core.runtime.Status;
018:        import org.eclipse.osgi.util.NLS;
019:        import org.eclipse.swt.SWT;
020:        import org.eclipse.swt.graphics.Color;
021:        import org.eclipse.swt.graphics.Image;
022:        import org.eclipse.swt.layout.GridData;
023:        import org.eclipse.swt.layout.GridLayout;
024:        import org.eclipse.swt.widgets.Composite;
025:        import org.eclipse.swt.widgets.Control;
026:        import org.eclipse.swt.widgets.Label;
027:        import org.eclipse.swt.widgets.Text;
028:        import org.eclipse.ui.PlatformUI;
029:        import org.eclipse.ui.forms.events.HyperlinkAdapter;
030:        import org.eclipse.ui.forms.events.HyperlinkEvent;
031:        import org.eclipse.ui.forms.widgets.FormText;
032:        import org.eclipse.ui.forms.widgets.FormToolkit;
033:        import org.eclipse.ui.forms.widgets.ImageHyperlink;
034:        import org.eclipse.ui.forms.widgets.TableWrapData;
035:        import org.eclipse.ui.forms.widgets.TableWrapLayout;
036:        import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin;
037:        import org.eclipse.ui.internal.cheatsheets.ICheatSheetResource;
038:        import org.eclipse.ui.internal.cheatsheets.Messages;
039:        import org.eclipse.ui.internal.cheatsheets.data.AbstractExecutable;
040:        import org.eclipse.ui.internal.cheatsheets.data.AbstractSubItem;
041:        import org.eclipse.ui.internal.cheatsheets.data.ConditionalSubItem;
042:        import org.eclipse.ui.internal.cheatsheets.data.IParserTags;
043:        import org.eclipse.ui.internal.cheatsheets.data.Item;
044:        import org.eclipse.ui.internal.cheatsheets.data.RepeatedSubItem;
045:        import org.eclipse.ui.internal.cheatsheets.data.SubItem;
046:
047:        public class CoreItem extends ViewItem {
048:
049:            protected boolean buttonsHandled = false;
050:
051:            private static final int SUBITEM_COLUMNS = 6;
052:
053:            /**
054:             * Constructor for CoreItem.
055:             * @param parent
056:             * @param contentItem
057:             */
058:            public CoreItem(CheatSheetPage page, Item item, Color itemColor,
059:                    CheatSheetViewer viewer) {
060:                super (page, item, itemColor, viewer);
061:            }
062:
063:            private void createButtonComposite() {
064:                buttonComposite = page.getToolkit().createComposite(
065:                        bodyWrapperComposite);
066:                GridLayout buttonlayout = new GridLayout(1, false);
067:                buttonlayout.marginHeight = 2;
068:                buttonlayout.marginWidth = 2;
069:                buttonlayout.verticalSpacing = 2;
070:
071:                TableWrapData buttonData = new TableWrapData(TableWrapData.FILL);
072:
073:                buttonComposite.setLayout(buttonlayout);
074:                buttonComposite.setLayoutData(buttonData);
075:                buttonComposite.setBackground(itemColor);
076:
077:            }
078:
079:            private void createButtons(AbstractExecutable executable) {
080:                /*
081:                 * Actions are disabled while inside dialogs.
082:                 */
083:                boolean isActionShown = false;
084:                if (executable != null && !isInDialogMode()) {
085:                    isActionShown = true;
086:                    final ImageHyperlink startButton = createButtonWithText(
087:                            buttonComposite,
088:                            CheatSheetPlugin
089:                                    .getPlugin()
090:                                    .getImage(
091:                                            ICheatSheetResource.CHEATSHEET_ITEM_BUTTON_START),
092:                            this , itemColor, Messages.PERFORM_TASK_TOOLTIP);
093:                    startButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP,
094:                            true, false));
095:                    startButton.addHyperlinkListener(new HyperlinkAdapter() {
096:                        public void linkActivated(HyperlinkEvent e) {
097:                            viewer.runPerformExecutable(startButton);
098:                        }
099:                    });
100:                }
101:                if (!isActionShown || executable.isConfirm()
102:                        || !executable.isRequired()) {
103:                    final ImageHyperlink completeButton = createButtonWithText(
104:                            buttonComposite,
105:                            CheatSheetPlugin
106:                                    .getPlugin()
107:                                    .getImage(
108:                                            ICheatSheetResource.CHEATSHEET_ITEM_BUTTON_COMPLETE),
109:                            this , itemColor, Messages.COMPLETE_TASK_TOOLTIP);
110:                    completeButton.addHyperlinkListener(new HyperlinkAdapter() {
111:                        public void linkActivated(HyperlinkEvent e) {
112:                            viewer.advanceItem(completeButton, true);
113:                        }
114:                    });
115:                }
116:                if (item.isSkip()) {
117:                    final ImageHyperlink skipButton = createButtonWithText(
118:                            buttonComposite,
119:                            CheatSheetPlugin.getPlugin().getImage(
120:                                    ICheatSheetResource.CHEATSHEET_ITEM_SKIP),
121:                            this , itemColor, Messages.SKIP_TASK_TOOLTIP);
122:                    skipButton.addHyperlinkListener(new HyperlinkAdapter() {
123:                        public void linkActivated(HyperlinkEvent e) {
124:                            viewer.advanceItem(skipButton, false);
125:                        }
126:                    });
127:                }
128:            }
129:
130:            private void createSubItemButtonComposite() {
131:                buttonComposite = page.getToolkit().createComposite(
132:                        bodyWrapperComposite);
133:
134:                TableWrapLayout xbuttonlayout = new TableWrapLayout();
135:                xbuttonlayout.numColumns = SUBITEM_COLUMNS;
136:                xbuttonlayout.leftMargin = 0;
137:                xbuttonlayout.rightMargin = 0;
138:                xbuttonlayout.horizontalSpacing = 0;
139:
140:                TableWrapData xbuttonData = new TableWrapData(
141:                        TableWrapData.FILL);
142:
143:                buttonComposite.setLayout(xbuttonlayout);
144:                buttonComposite.setLayoutData(xbuttonData);
145:                buttonComposite.setBackground(itemColor);
146:            }
147:
148:            private void createSubItemButtons(SubItem sub, String this Value,
149:                    int index) {
150:                int added = 0;
151:                if (index != 0) {
152:                    addSeparator();
153:                }
154:                final int LABEL_MARGIN = 5; // space to the left and right of the label
155:                SubItemCompositeHolder holder = new SubItemCompositeHolder(sub);
156:
157:                //Spacer label added.
158:                Label checkDoneLabel = page.getToolkit().createLabel(
159:                        buttonComposite, null);
160:                checkDoneLabel.setImage(CheatSheetPlugin.getPlugin().getImage(
161:                        ICheatSheetResource.CHEATSHEET_ITEM_COMPLETE));
162:                checkDoneLabel.setVisible(false);
163:                checkDoneLabel.setBackground(itemColor);
164:                holder.setCheckDoneLabel(checkDoneLabel);
165:                added++;
166:
167:                //Now add the label.
168:                String labelText = null;
169:                if (this Value != null) {
170:                    labelText = performLineSubstitution(sub.getLabel(),
171:                            "${this}", this Value); //$NON-NLS-1$
172:                } else {
173:                    labelText = sub.getLabel();
174:                }
175:                Text subitemLabel = new Text(buttonComposite, SWT.READ_ONLY
176:                        + SWT.WRAP);
177:                subitemLabel.setText(labelText);
178:                TableWrapData labelData = new TableWrapData();
179:                labelData.indent = LABEL_MARGIN;
180:                subitemLabel.setLayoutData(labelData);
181:                subitemLabel.setBackground(itemColor);
182:                holder.setSubitemLabel(subitemLabel);
183:                added++;
184:
185:                // Add some space to the right of the label
186:
187:                Label spacer = page.getToolkit().createLabel(buttonComposite,
188:                        null);
189:                TableWrapData spacerData = new TableWrapData();
190:                spacerData.maxWidth = 0;
191:                spacerData.indent = LABEL_MARGIN;
192:                spacer.setLayoutData(spacerData);
193:                added++;
194:
195:                AbstractExecutable subExecutable = null;
196:                if (sub.getPerformWhen() != null) {
197:                    sub.getPerformWhen().setSelectedExecutable(
198:                            viewer.getManager());
199:                    subExecutable = sub.getPerformWhen()
200:                            .getSelectedExecutable();
201:                } else {
202:                    subExecutable = sub.getExecutable();
203:                }
204:
205:                /*
206:                 * Actions are disabled while inside dialogs.
207:                 */
208:                final int fi = index;
209:                ImageHyperlink startButton = null;
210:                boolean isActionShown = false;
211:                if (subExecutable != null && !isInDialogMode()) {
212:                    added++;
213:                    isActionShown = true;
214:                    startButton = createButton(
215:                            buttonComposite,
216:                            CheatSheetPlugin
217:                                    .getPlugin()
218:                                    .getImage(
219:                                            ICheatSheetResource.CHEATSHEET_ITEM_BUTTON_START),
220:                            this , itemColor, Messages.PERFORM_TASK_TOOLTIP);
221:                    final ImageHyperlink finalStartButton = startButton;
222:                    startButton.addHyperlinkListener(new HyperlinkAdapter() {
223:                        public void linkActivated(HyperlinkEvent e) {
224:                            viewer.runSubItemPerformExecutable(
225:                                    finalStartButton, fi);
226:                        }
227:                    });
228:                    holder.setStartButton(startButton);
229:                }
230:                if (!isActionShown || subExecutable.isConfirm()
231:                        || !subExecutable.isRequired()) {
232:                    added++;
233:                    final ImageHyperlink completeButton = createButton(
234:                            buttonComposite,
235:                            CheatSheetPlugin
236:                                    .getPlugin()
237:                                    .getImage(
238:                                            ICheatSheetResource.CHEATSHEET_ITEM_BUTTON_COMPLETE),
239:                            this , itemColor, Messages.COMPLETE_TASK_TOOLTIP);
240:                    completeButton.addHyperlinkListener(new HyperlinkAdapter() {
241:                        public void linkActivated(HyperlinkEvent e) {
242:                            viewer.advanceSubItem(completeButton, true, fi);
243:                        }
244:                    });
245:                    holder.setCompleteButton(completeButton);
246:                }
247:                if (sub.isSkip()) {
248:                    added++;
249:                    final ImageHyperlink skipButton = createButton(
250:                            buttonComposite,
251:                            CheatSheetPlugin.getPlugin().getImage(
252:                                    ICheatSheetResource.CHEATSHEET_ITEM_SKIP),
253:                            this , itemColor, Messages.SKIP_TASK_TOOLTIP);
254:                    skipButton.addHyperlinkListener(new HyperlinkAdapter() {
255:                        public void linkActivated(HyperlinkEvent e) {
256:                            viewer.advanceSubItem(skipButton, false, fi);
257:                        }
258:                    });
259:                    holder.setSkipButton(skipButton);
260:                }
261:
262:                while (added < SUBITEM_COLUMNS) {
263:                    // Add filler labels as needed to complete the row
264:                    Label filler = page.getToolkit().createLabel(
265:                            buttonComposite, null);
266:                    TableWrapData fillerData = new TableWrapData();
267:                    fillerData.maxWidth = 0;
268:                    filler.setLayoutData(fillerData);
269:                    added++;
270:                }
271:                holder.setThisValue(this Value);
272:                listOfSubItemCompositeHolders.add(holder);
273:            }
274:
275:            private void addSeparator() {
276:                Label pad = page.getToolkit()
277:                        .createLabel(buttonComposite, null);
278:                TableWrapData padData = new TableWrapData();
279:                padData.maxWidth = 0;
280:                pad.setLayoutData(padData);
281:                Label separator = new Label(buttonComposite, SWT.SEPARATOR
282:                        + SWT.HORIZONTAL);
283:                TableWrapData separatorData = new TableWrapData();
284:                separatorData.align = TableWrapData.FILL;
285:                separatorData.grabHorizontal = true;
286:                separatorData.maxHeight = 1;
287:                separatorData.valign = TableWrapData.MIDDLE;
288:                separator.setLayoutData(separatorData);
289:                for (int i = 3; i <= SUBITEM_COLUMNS; i++) {
290:                    Label filler = page.getToolkit().createLabel(
291:                            buttonComposite, null);
292:                    TableWrapData fillerData = new TableWrapData();
293:                    fillerData.maxWidth = 0;
294:                    filler.setLayoutData(fillerData);
295:                }
296:            }
297:
298:            private AbstractExecutable getExecutable() {
299:                AbstractExecutable executable = item.getExecutable();
300:                if (executable == null) {
301:                    if (item.getPerformWhen() != null) {
302:                        executable = item.getPerformWhen()
303:                                .getSelectedExecutable();
304:                    }
305:                }
306:                return executable;
307:            }
308:
309:            private AbstractExecutable getExecutable(int index) {
310:                if (item.getSubItems() != null && item.getSubItems().size() > 0
311:                        && listOfSubItemCompositeHolders != null) {
312:                    SubItemCompositeHolder s = (SubItemCompositeHolder) listOfSubItemCompositeHolders
313:                            .get(index);
314:                    if (s != null) {
315:                        SubItem subItem = s.getSubItem();
316:                        AbstractExecutable executable = subItem.getExecutable();
317:                        if (executable == null) {
318:                            if (subItem.getPerformWhen() != null) {
319:                                executable = subItem.getPerformWhen()
320:                                        .getSelectedExecutable();
321:                            }
322:                        }
323:                        return executable;
324:                    }
325:                }
326:                return null;
327:            }
328:
329:            public ArrayList getListOfSubItemCompositeHolders() {
330:                return listOfSubItemCompositeHolders;
331:            }
332:
333:            private ImageHyperlink getStartButton() {
334:                if (item.getSubItems() != null && item.getSubItems().size() > 0) {
335:                    // Bug 137332 - don't look in items with subitems
336:                    return null;
337:                }
338:                if (buttonComposite != null) {
339:                    Control[] controls = buttonComposite.getChildren();
340:                    for (int i = 0; i < controls.length; i++) {
341:                        Control control = controls[i];
342:                        if (control instanceof  ImageHyperlink) {
343:                            String toolTipText = control.getToolTipText();
344:                            if (toolTipText != null
345:                                    && (toolTipText
346:                                            .equals(Messages.PERFORM_TASK_TOOLTIP) || toolTipText
347:                                            .equals(Messages.RESTART_TASK_TOOLTIP))) {
348:                                return (ImageHyperlink) control;
349:                            }
350:                        }
351:                    }
352:                }
353:                return null;
354:            }
355:
356:            /**
357:             * @see org.eclipse.ui.internal.cheatsheets.ViewItem#handleButtons()
358:             */
359:            /*package*/void handleButtons() {
360:                if (item.isDynamic()) {
361:                    handleDynamicButtons();
362:                    return;
363:                } else if (item.getSubItems() != null
364:                        && item.getSubItems().size() > 0) {
365:                    handleSubButtons();
366:                }
367:
368:                if (buttonsHandled)
369:                    return;
370:
371:                createButtonComposite();
372:                createButtons(item.getExecutable());
373:                buttonsHandled = true;
374:            }
375:
376:            private void handleDynamicButtons() {
377:                if (item.getSubItems() != null && item.getSubItems().size() > 0) {
378:                    handleDynamicSubItemButtons();
379:                } else if (item.getPerformWhen() != null) {
380:                    handlePerformWhenButtons();
381:                }
382:            }
383:
384:            private void handleDynamicSubItemButtons() {
385:                boolean refreshRequired = false;
386:                if (buttonComposite != null) {
387:                    Control[] children = buttonComposite.getChildren();
388:                    for (int i = 0; i < children.length; i++) {
389:                        Control control = children[i];
390:                        control.dispose();
391:                    }
392:
393:                    refreshRequired = true;
394:                } else {
395:                    createSubItemButtonComposite();
396:                }
397:
398:                //Instantiate the list to store the sub item composites.
399:                listOfSubItemCompositeHolders = new ArrayList(20);
400:
401:                //loop throught the number of sub items, make a new composite for each sub item.
402:                //Add the spacer, the label, then the buttons that are applicable for each sub item.
403:                int i = 0;
404:                for (Iterator iter = item.getSubItems().iterator(); iter
405:                        .hasNext(); i++) {
406:                    AbstractSubItem subItem = (AbstractSubItem) iter.next();
407:                    if (subItem instanceof  RepeatedSubItem) {
408:
409:                        //Get the sub item to add.
410:                        RepeatedSubItem repeatedSubItem = (RepeatedSubItem) subItem;
411:                        String values = repeatedSubItem.getValues();
412:                        values = viewer.getManager().getVariableData(values);
413:                        if (values == null
414:                                || values.length() <= 0
415:                                || (values.startsWith("${") && values.endsWith("}"))) { //$NON-NLS-1$ //$NON-NLS-2$
416:                            String message = NLS
417:                                    .bind(Messages.ERROR_DATA_MISSING_LOG,
418:                                            (new Object[] { repeatedSubItem
419:                                                    .getValues() }));
420:                            IStatus status = new Status(IStatus.ERROR,
421:                                    ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID,
422:                                    IStatus.OK, message, null);
423:                            CheatSheetPlugin.getPlugin().getLog().log(status);
424:
425:                            status = new Status(IStatus.ERROR,
426:                                    ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID,
427:                                    IStatus.OK, Messages.ERROR_DATA_MISSING,
428:                                    null);
429:                            CheatSheetPlugin.getPlugin().getLog().log(status);
430:                            org.eclipse.jface.dialogs.ErrorDialog.openError(
431:                                    PlatformUI.getWorkbench()
432:                                            .getActiveWorkbenchWindow()
433:                                            .getShell(), null, null, status);
434:                            break;
435:                        }
436:
437:                        SubItem sub = (SubItem) repeatedSubItem.getSubItems()
438:                                .get(0);
439:
440:                        StringTokenizer tokenizer = new StringTokenizer(values,
441:                                ","); //$NON-NLS-1$
442:                        while (tokenizer.hasMoreTokens()) {
443:                            String value = tokenizer.nextToken();
444:                            createSubItemButtons(sub, value, i++);
445:                        }
446:
447:                        // Decrement the counter by because the outer loop increments it prior to the next iteration
448:                        i--;
449:                    } else if (subItem instanceof  ConditionalSubItem) {
450:                        //Get the sub item to add.
451:                        ConditionalSubItem sub = (ConditionalSubItem) subItem;
452:
453:                        sub.setSelectedSubItem(viewer.getManager());
454:                        SubItem selectedSubItem = sub.getSelectedSubItem();
455:
456:                        if (selectedSubItem == null) {
457:                            String message = NLS
458:                                    .bind(
459:                                            Messages.ERROR_CONDITIONAL_DATA_MISSING_LOG,
460:                                            (new Object[] { sub.getCondition(),
461:                                                    getItem().getTitle() }));
462:                            IStatus status = new Status(IStatus.ERROR,
463:                                    ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID,
464:                                    IStatus.OK, message, null);
465:                            CheatSheetPlugin.getPlugin().getLog().log(status);
466:
467:                            status = new Status(IStatus.ERROR,
468:                                    ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID,
469:                                    IStatus.OK, Messages.ERROR_DATA_MISSING,
470:                                    null);
471:                            CheatSheetPlugin.getPlugin().getLog().log(status);
472:                            org.eclipse.jface.dialogs.ErrorDialog.openError(
473:                                    PlatformUI.getWorkbench()
474:                                            .getActiveWorkbenchWindow()
475:                                            .getShell(), null, null, status);
476:                            break;
477:                        }
478:
479:                        createSubItemButtons(selectedSubItem, null, i);
480:                    } else if (subItem instanceof  SubItem) {
481:                        createSubItemButtons((SubItem) subItem, null, i);
482:                    }
483:                }
484:
485:                if (refreshRequired) {
486:                    refresh(buttonComposite);
487:                }
488:            }
489:
490:            private void handlePerformWhenButtons() {
491:                boolean refreshRequired = false;
492:
493:                if (buttonComposite != null) {
494:                    Control[] controls = buttonComposite.getChildren();
495:                    for (int i = 0; i < controls.length; i++) {
496:                        Control control = controls[i];
497:                        if (control instanceof  ImageHyperlink) {
498:                            control.dispose();
499:                        }
500:                    }
501:
502:                    refreshRequired = true;
503:                } else {
504:                    createButtonComposite();
505:                }
506:
507:                item.getPerformWhen()
508:                        .setSelectedExecutable(viewer.getManager());
509:                AbstractExecutable performExecutable = item.getPerformWhen()
510:                        .getSelectedExecutable();
511:
512:                createButtons(performExecutable);
513:
514:                if (refreshRequired) {
515:                    refresh(buttonComposite);
516:                }
517:            }
518:
519:            private void handleSubButtons() {
520:                if (buttonsHandled)
521:                    return;
522:                //Instantiate the list to store the sub item composites.
523:                listOfSubItemCompositeHolders = new ArrayList(20);
524:
525:                ArrayList sublist = item.getSubItems();
526:
527:                createSubItemButtonComposite();
528:
529:                //loop throught the number of sub items, make a new composite for each sub item.
530:                //Add the spacer, the label, then the buttons that are applicable for each sub item.
531:                for (int i = 0; i < sublist.size(); i++) {
532:                    createSubItemButtons((SubItem) sublist.get(i), null, i);
533:                }
534:                buttonsHandled = true;
535:            }
536:
537:            /*package*/
538:            boolean hasConfirm() {
539:                AbstractExecutable executable = getExecutable();
540:
541:                if (executable == null || executable.isConfirm()) {
542:                    return true;
543:                }
544:                return false;
545:            }
546:
547:            /*package*/
548:            boolean hasConfirm(int index) {
549:                AbstractExecutable executable = getExecutable(index);
550:
551:                if (executable == null || executable.isConfirm()) {
552:                    return true;
553:                }
554:                return false;
555:            }
556:
557:            public String performLineSubstitution(String line, String variable,
558:                    String value) {
559:                StringBuffer buffer = new StringBuffer(line.length());
560:
561:                StringDelimitedTokenizer tokenizer = new StringDelimitedTokenizer(
562:                        line, variable);
563:                boolean addValue = false;
564:
565:                while (tokenizer.hasMoreTokens()) {
566:                    if (addValue) {
567:                        buffer.append(value);
568:                    }
569:                    buffer.append(tokenizer.nextToken());
570:                    addValue = true;
571:                }
572:                if (tokenizer.endsWithDelimiter()) {
573:                    buffer.append(value);
574:                }
575:
576:                return buffer.toString();
577:            }
578:
579:            /*package*/
580:            IStatus runExecutable(CheatSheetManager csm) {
581:                return runExecutable(getExecutable(), csm);
582:            }
583:
584:            IStatus runExecutable(AbstractExecutable executable,
585:                    CheatSheetManager csm) {
586:                if (executable != null) {
587:                    return executable.execute(csm);
588:                }
589:                return Status.OK_STATUS;
590:            }
591:
592:            /*package*/
593:            byte runSubItemExecutable(CheatSheetManager csm, int index) {
594:                if (item.getSubItems() != null && item.getSubItems().size() > 0
595:                        && listOfSubItemCompositeHolders != null) {
596:                    SubItemCompositeHolder s = (SubItemCompositeHolder) listOfSubItemCompositeHolders
597:                            .get(index);
598:                    if (s != null) {
599:                        AbstractExecutable executable = getExecutable(index);
600:
601:                        if (executable != null) {
602:                            try {
603:                                if (s.getThisValue() != null) {
604:                                    csm.setData("this", s.getThisValue()); //$NON-NLS-1$
605:                                }
606:                                IStatus status = runExecutable(executable, csm);
607:                                if (status.isOK()) {
608:                                    return VIEWITEM_ADVANCE;
609:                                }
610:                                if (status.getSeverity() == IStatus.ERROR) {
611:                                    CheatSheetPlugin.getPlugin().getLog().log(
612:                                            status);
613:                                    org.eclipse.jface.dialogs.ErrorDialog
614:                                            .openError(PlatformUI
615:                                                    .getWorkbench()
616:                                                    .getActiveWorkbenchWindow()
617:                                                    .getShell(), null, null,
618:                                                    status);
619:                                }
620:                                return VIEWITEM_DONOT_ADVANCE;
621:                            } finally {
622:                                if (s.getThisValue() != null) {
623:                                    csm.setData("this", null); //$NON-NLS-1$
624:                                }
625:                            }
626:                        }
627:                    }
628:                }
629:                return VIEWITEM_ADVANCE;
630:            }
631:
632:            /*package*/void setButtonsHandled(boolean handled) {
633:                buttonsHandled = handled;
634:            }
635:
636:            /*package*/void setIncomplete() {
637:                super .setIncomplete();
638:
639:                //check for sub items and reset their icons.
640:                ArrayList l = getListOfSubItemCompositeHolders();
641:                if (l != null) {
642:                    for (int j = 0; j < l.size(); j++) {
643:                        SubItemCompositeHolder s = (SubItemCompositeHolder) l
644:                                .get(j);
645:                        if (s.isCompleted() || s.isSkipped())
646:                            s.getCheckDoneLabel().setVisible(false); //setImage(null);
647:                        if (s.getStartButton() != null) {
648:                            s
649:                                    .getStartButton()
650:                                    .setImage(
651:                                            CheatSheetPlugin
652:                                                    .getPlugin()
653:                                                    .getImage(
654:                                                            ICheatSheetResource.CHEATSHEET_ITEM_BUTTON_START));
655:                            s.getStartButton().setToolTipText(
656:                                    Messages.PERFORM_TASK_TOOLTIP);
657:                        }
658:                    }
659:                }
660:            }
661:
662:            /*package*/void setRestartImage() {
663:                ImageHyperlink startButton = getStartButton();
664:                if (startButton != null) {
665:                    startButton
666:                            .setImage(CheatSheetPlugin
667:                                    .getPlugin()
668:                                    .getImage(
669:                                            ICheatSheetResource.CHEATSHEET_ITEM_BUTTON_RESTART));
670:                    startButton.setText(Messages.RESTART_TASK_TOOLTIP);
671:                    startButton.setToolTipText(Messages.RESTART_TASK_TOOLTIP);
672:                }
673:            }
674:
675:            /*package*/void setStartImage() {
676:                ImageHyperlink startButton = getStartButton();
677:                if (startButton != null) {
678:                    startButton.setImage(CheatSheetPlugin.getPlugin().getImage(
679:                            ICheatSheetResource.CHEATSHEET_ITEM_BUTTON_START));
680:                    if (startButton.getText() != null) {
681:                        startButton.setText(Messages.PERFORM_TASK_TOOLTIP);
682:                    }
683:                    startButton.setToolTipText(Messages.PERFORM_TASK_TOOLTIP);
684:                }
685:            }
686:
687:            boolean hasCompletionMessage() {
688:                return item.getCompletionMessage() != null;
689:            }
690:
691:            /*
692:             * (non-Javadoc)
693:             * Create a composite to hold the message defined in an onCompletion element
694:             * and a button to advance to the next step or return to the introduction if 
695:             * this is the last step.
696:             */
697:            void createCompletionComposite(boolean isFinalItem) {
698:                String completionMessage = viewer.getManager()
699:                        .performVariableSubstitution(
700:                                item.getCompletionMessage());
701:                if (completionMessage != null) {
702:                    Color backgroundColor = bodyWrapperComposite
703:                            .getBackground();
704:                    completionComposite = page.getToolkit().createComposite(
705:                            bodyWrapperComposite);
706:                    TableWrapLayout completionlayout = new TableWrapLayout();
707:                    completionlayout.numColumns = 1;
708:
709:                    TableWrapData completionData = new TableWrapData(
710:                            TableWrapData.FILL);
711:
712:                    completionComposite.setLayout(completionlayout);
713:                    completionComposite.setLayoutData(completionData);
714:                    completionComposite.setBackground(backgroundColor);
715:
716:                    FormText completionText = page.getToolkit().createFormText(
717:                            completionComposite, false);
718:                    completionText.setText(completionMessage, completionMessage
719:                            .startsWith(IParserTags.FORM_START_TAG), false);
720:                    completionText.setBackground(backgroundColor);
721:                    final ImageHyperlink completeButton = createButtonWithText(
722:                            completionComposite,
723:                            getCompletionButtonIcon(isFinalItem), this ,
724:                            backgroundColor,
725:                            getCompletionButtonTooltip(isFinalItem));
726:                    completeButton.addHyperlinkListener(new HyperlinkAdapter() {
727:                        public void linkActivated(HyperlinkEvent e) {
728:                            viewer.advanceItem(completeButton, true);
729:                        }
730:                    });
731:                    completionComposite.setVisible(false);
732:                    // The line below is necessary because without it the color of
733:                    // the composite containing the button does not get set
734:                    setBackgroundColor(completionComposite, backgroundColor);
735:                    refresh(completionComposite);
736:                }
737:            }
738:
739:            private Image getCompletionButtonIcon(boolean isFinalItem) {
740:                if (isFinalItem) {
741:                    return CheatSheetPlugin.getPlugin().getImage(
742:                            ICheatSheetResource.CHEATSHEET_RETURN);
743:                }
744:                return CheatSheetPlugin.getPlugin().getImage(
745:                        ICheatSheetResource.CHEATSHEET_ITEM_BUTTON_COMPLETE);
746:            }
747:
748:            private String getCompletionButtonTooltip(boolean isFinalItem) {
749:                if (isFinalItem) {
750:                    return Messages.RETURN_TO_INTRO_TOOLTIP;
751:                }
752:                return Messages.ADVANCE_TASK_TOOLTIP;
753:            }
754:
755:            private void refresh(Composite composite) {
756:                composite.layout();
757:                getMainItemComposite().layout();
758:                page.getForm().reflow(true);
759:            }
760:
761:            public void refreshItem() {
762:                if (buttonComposite != null) {
763:                    refresh(buttonComposite);
764:                }
765:            }
766:
767:            protected void setFocus() {
768:                ArrayList list = getListOfSubItemCompositeHolders();
769:                Control subitemLabel = null;
770:                SubItemCompositeHolder holder = null;
771:                if (list != null) {
772:                    for (Iterator iter = list.iterator(); iter.hasNext()
773:                            && subitemLabel == null;) {
774:                        holder = (SubItemCompositeHolder) iter.next();
775:                        if (!holder.isCompleted() && !holder.isSkipped()) {
776:                            subitemLabel = holder.getSubitemLabel();
777:                        }
778:                    }
779:                }
780:                if (subitemLabel != null) {
781:                    FormToolkit.ensureVisible(subitemLabel);
782:                    if (holder.getStartButton() != null) {
783:                        holder.getStartButton().setFocus();
784:                    } else if (holder.getCompleteButton() != null) {
785:                        holder.getCompleteButton().setFocus();
786:                    }
787:                } else {
788:                    FormToolkit.ensureVisible(getMainItemComposite());
789:                    super.setFocus();
790:                }
791:            }
792:
793:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.