Source Code Cross Referenced for IntroURL.java in  » IDE-Eclipse » ui » org » eclipse » ui » internal » intro » impl » model » url » 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.intro.impl.model.url 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 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.intro.impl.model.url;
011:
012:        import java.util.Enumeration;
013:        import java.util.Hashtable;
014:        import java.util.Properties;
015:
016:        import org.eclipse.core.commands.ParameterizedCommand;
017:        import org.eclipse.core.commands.common.CommandException;
018:        import org.eclipse.jface.action.Action;
019:        import org.eclipse.jface.action.IAction;
020:        import org.eclipse.jface.util.Geometry;
021:        import org.eclipse.swt.browser.Browser;
022:        import org.eclipse.swt.custom.BusyIndicator;
023:        import org.eclipse.swt.graphics.Rectangle;
024:        import org.eclipse.swt.widgets.Display;
025:        import org.eclipse.ui.IActionDelegate;
026:        import org.eclipse.ui.IWorkbench;
027:        import org.eclipse.ui.IWorkbenchWindow;
028:        import org.eclipse.ui.IWorkbenchWindowActionDelegate;
029:        import org.eclipse.ui.PlatformUI;
030:        import org.eclipse.ui.commands.ICommandService;
031:        import org.eclipse.ui.handlers.IHandlerService;
032:        import org.eclipse.ui.internal.RectangleAnimation;
033:        import org.eclipse.ui.internal.intro.impl.IIntroConstants;
034:        import org.eclipse.ui.internal.intro.impl.IntroPlugin;
035:        import org.eclipse.ui.internal.intro.impl.Messages;
036:        import org.eclipse.ui.internal.intro.impl.model.AbstractIntroElement;
037:        import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage;
038:        import org.eclipse.ui.internal.intro.impl.model.IntroLaunchBarElement;
039:        import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot;
040:        import org.eclipse.ui.internal.intro.impl.model.IntroPartPresentation;
041:        import org.eclipse.ui.internal.intro.impl.model.IntroTheme;
042:        import org.eclipse.ui.internal.intro.impl.model.IntroURLAction;
043:        import org.eclipse.ui.internal.intro.impl.model.loader.ExtensionPointManager;
044:        import org.eclipse.ui.internal.intro.impl.model.loader.ModelLoaderUtil;
045:        import org.eclipse.ui.internal.intro.impl.model.util.ModelUtil;
046:        import org.eclipse.ui.internal.intro.impl.parts.StandbyPart;
047:        import org.eclipse.ui.internal.intro.impl.presentations.BrowserIntroPartImplementation;
048:        import org.eclipse.ui.internal.intro.impl.presentations.IntroLaunchBar;
049:        import org.eclipse.ui.internal.intro.impl.util.DialogUtil;
050:        import org.eclipse.ui.internal.intro.impl.util.Log;
051:        import org.eclipse.ui.internal.intro.impl.util.StringUtil;
052:        import org.eclipse.ui.internal.intro.impl.util.Util;
053:        import org.eclipse.ui.intro.IIntroPart;
054:        import org.eclipse.ui.intro.IIntroSite;
055:        import org.eclipse.ui.intro.config.CustomizableIntroPart;
056:        import org.eclipse.ui.intro.config.IIntroAction;
057:        import org.eclipse.ui.intro.config.IIntroURL;
058:        import org.eclipse.ui.intro.config.IntroURLFactory;
059:
060:        /**
061:         * An intro url. An intro URL is a valid http url, with org.eclipse.ui.intro as
062:         * a host. This class holds all logic to execute Intro URL commands, ie: an
063:         * Intro URL knows how to execute itself.
064:         */
065:        public class IntroURL implements  IIntroURL {
066:
067:            /**
068:             * Intro URL constants.
069:             */
070:            public static final String INTRO_PROTOCOL = "http"; //$NON-NLS-1$
071:            public static final String INTRO_HOST_ID = "org.eclipse.ui.intro"; //$NON-NLS-1$
072:
073:            /**
074:             * Constants that represent Intro URL actions.
075:             */
076:            public static final String SET_STANDBY_MODE = "setStandbyMode"; //$NON-NLS-1$
077:            public static final String SHOW_STANDBY = "showStandby"; //$NON-NLS-1$
078:            public static final String CLOSE = "close"; //$NON-NLS-1$
079:            public static final String SHOW_HELP_TOPIC = "showHelpTopic"; //$NON-NLS-1$
080:            public static final String SHOW_HELP = "showHelp"; //$NON-NLS-1$
081:            public static final String OPEN_BROWSER = "openBrowser"; //$NON-NLS-1$
082:            public static final String OPEN_URL = "openURL"; //$NON-NLS-1$
083:            public static final String RUN_ACTION = "runAction"; //$NON-NLS-1$
084:            public static final String SHOW_PAGE = "showPage"; //$NON-NLS-1$
085:            public static final String SHOW_MESSAGE = "showMessage"; //$NON-NLS-1$
086:            public static final String NAVIGATE = "navigate"; //$NON-NLS-1$
087:            public static final String SWITCH_TO_LAUNCH_BAR = "switchToLaunchBar"; //$NON-NLS-1$
088:            public static final String EXECUTE = "execute"; //$NON-NLS-1$
089:
090:            /**
091:             * Constants that represent valid action keys.
092:             */
093:            public static final String KEY_ID = "id"; //$NON-NLS-1$
094:            public static final String KEY_PLUGIN_ID = "pluginId"; //$NON-NLS-1$
095:            public static final String KEY_CLASS = "class"; //$NON-NLS-1$
096:            public static final String KEY_STANDBY = "standby"; //$NON-NLS-1$
097:            public static final String KEY_PART_ID = "partId"; //$NON-NLS-1$
098:            public static final String KEY_INPUT = "input"; //$NON-NLS-1$
099:            public static final String KEY_MESSAGE = "message"; //$NON-NLS-1$
100:            public static final String KEY_URL = "url"; //$NON-NLS-1$
101:            public static final String KEY_DIRECTION = "direction"; //$NON-NLS-1$
102:            public static final String KEY_EMBED = "embed"; //$NON-NLS-1$
103:            public static final String KEY_EMBED_TARGET = "embedTarget"; //$NON-NLS-1$
104:            public static final String KEY_DECODE = "decode"; //$NON-NLS-1$
105:            public static final String KEY_COMAND = "command"; //$NON-NLS-1$
106:
107:            public static final String VALUE_BACKWARD = "backward"; //$NON-NLS-1$
108:            public static final String VALUE_FORWARD = "forward"; //$NON-NLS-1$
109:            public static final String VALUE_HOME = "home"; //$NON-NLS-1$
110:            public static final String VALUE_TRUE = "true"; //$NON-NLS-1$
111:            public static final String VALUE_FALSE = "false"; //$NON-NLS-1$
112:
113:            private String action = null;
114:            private Properties parameters = null;
115:
116:            /**
117:             * Prevent creation. Must be created through an IntroURLParser. This
118:             * constructor assumed we have a valid intro url.
119:             * 
120:             * @param url
121:             */
122:            IntroURL(String action, Properties parameters) {
123:                this .action = action;
124:                this .parameters = parameters;
125:            }
126:
127:            /**
128:             * Executes whatever valid Intro action is embedded in this Intro URL.
129:             * 
130:             */
131:            public boolean execute() {
132:                final boolean[] result = new boolean[1];
133:                Display display = Display.getCurrent();
134:
135:                BusyIndicator.showWhile(display, new Runnable() {
136:
137:                    public void run() {
138:                        result[0] = doExecute();
139:                    }
140:                });
141:                return result[0];
142:            }
143:
144:            protected boolean doExecute() {
145:                if (Log.logInfo) {
146:                    String msg = StringUtil
147:                            .concat("Running Intro URL action ", action, //$NON-NLS-1$
148:                                    " with parameters: ", parameters.toString()).toString(); //$NON-NLS-1$
149:                    Log.info(msg);
150:                }
151:
152:                // check for all supported Intro actions first.
153:                if (action.equals(CLOSE))
154:                    return closeIntro();
155:
156:                else if (action.equals(SET_STANDBY_MODE))
157:                    // Sets the state of the intro part. Does not care about passing
158:                    // input to the part.
159:                    return setStandbyState(getParameter(KEY_STANDBY));
160:
161:                else if (action.equals(SHOW_STANDBY))
162:                    return handleStandbyState(getParameter(KEY_PART_ID),
163:                            getParameter(KEY_INPUT));
164:
165:                else if (action.equals(SHOW_HELP))
166:                    // display the full Help System.
167:                    return showHelp();
168:
169:                else if (action.equals(SHOW_HELP_TOPIC))
170:                    // display a Help System Topic. It can be displayed in the Help
171:                    // system window, or embedded as an intro page.
172:                    // return showHelpTopic(getParameter(KEY_ID));
173:                    return showHelpTopic(getParameter(KEY_ID),
174:                            getParameter(KEY_EMBED),
175:                            getParameter(KEY_EMBED_TARGET));
176:
177:                else if (action.equals(OPEN_BROWSER))
178:                    // display url in external browser
179:                    return openBrowser(getParameter(KEY_URL),
180:                            getParameter(KEY_PLUGIN_ID));
181:
182:                if (action.equals(OPEN_URL))
183:                    // display url embedded in intro browser.
184:                    return openURL(getParameter(KEY_URL),
185:                            getParameter(KEY_PLUGIN_ID));
186:
187:                else if (action.equals(RUN_ACTION))
188:                    // run an Intro action. Get the pluginId and the class keys. Pass
189:                    // the parameters and the standby state.
190:                    return runAction(getParameter(KEY_PLUGIN_ID),
191:                            getParameter(KEY_CLASS), parameters,
192:                            getParameter(KEY_STANDBY));
193:
194:                else if (action.equals(EXECUTE))
195:                    // execute a serialized command
196:                    return executeCommand(getParameter(KEY_COMAND),
197:                            getParameter(KEY_STANDBY));
198:
199:                else if (action.equals(SHOW_PAGE))
200:                    // display an Intro Page.
201:                    return showPage(getParameter(KEY_ID),
202:                            getParameter(KEY_STANDBY));
203:
204:                else if (action.equals(SHOW_MESSAGE))
205:                    return showMessage(getParameter(KEY_MESSAGE));
206:
207:                else if (action.equals(NAVIGATE))
208:                    return navigate(getParameter(KEY_DIRECTION));
209:
210:                else if (action.equals(SWITCH_TO_LAUNCH_BAR))
211:                    return switchToLaunchBar();
212:
213:                else
214:                    return handleCustomAction();
215:            }
216:
217:            private boolean closeIntro() {
218:                // Relies on Workbench.
219:                return IntroPlugin.closeIntro();
220:            }
221:
222:            /**
223:             * Sets the into part to standby, and shows the passed standby part, with
224:             * the given input. Forces the Intro view to open, if not yet created.
225:             * 
226:             * @param partId
227:             * @param input
228:             */
229:            private boolean handleStandbyState(String partId, String input) {
230:                // set intro to standby mode. we know we have a customizable part.
231:                CustomizableIntroPart introPart = (CustomizableIntroPart) IntroPlugin
232:                        .getIntro();
233:                if (introPart == null)
234:                    introPart = (CustomizableIntroPart) IntroPlugin
235:                            .showIntro(true);
236:                // store the flag to indicate that standbypart is needed.
237:                introPart.getControl().setData(
238:                        IIntroConstants.SHOW_STANDBY_PART, VALUE_TRUE);
239:                IntroPlugin.setIntroStandby(true);
240:                StandbyPart standbyPart = (StandbyPart) introPart
241:                        .getAdapter(StandbyPart.class);
242:
243:                boolean success = standbyPart.showContentPart(partId, input);
244:                if (success)
245:                    return true;
246:
247:                // we do not have a valid partId or we failed to instantiate part or
248:                // create the part content, empty part will be shown. Signal failure.
249:                return false;
250:            }
251:
252:            /**
253:             * Set the Workbench Intro Part state. Forces the Intro view to open, if not
254:             * yet created.
255:             * 
256:             * @param state
257:             */
258:            private boolean setStandbyState(String state) {
259:                if (state == null)
260:                    return false;
261:                boolean standby = state.equals(VALUE_TRUE) ? true : false;
262:                IIntroPart introPart = IntroPlugin.showIntro(standby);
263:                if (introPart == null)
264:                    return false;
265:                return true;
266:            }
267:
268:            /**
269:             * Run an action
270:             */
271:            private boolean runAction(String pluginId, String className,
272:                    Properties parameters, String standbyState) {
273:
274:                Object actionObject = ModelLoaderUtil.createClassInstance(
275:                        pluginId, className);
276:                try {
277:                    if (actionObject instanceof  IIntroAction) {
278:                        IIntroAction introAction = (IIntroAction) actionObject;
279:                        IIntroSite site = IntroPlugin.getDefault()
280:                                .getIntroModelRoot().getPresentation()
281:                                .getIntroPart().getIntroSite();
282:                        introAction.run(site, parameters);
283:                    } else if (actionObject instanceof  IAction) {
284:                        IAction action = (IAction) actionObject;
285:                        action.run();
286:
287:                    } else if (actionObject instanceof  IActionDelegate) {
288:                        final IActionDelegate delegate = (IActionDelegate) actionObject;
289:                        if (delegate instanceof  IWorkbenchWindowActionDelegate)
290:                            ((IWorkbenchWindowActionDelegate) delegate)
291:                                    .init(PlatformUI.getWorkbench()
292:                                            .getActiveWorkbenchWindow());
293:                        Action proxy = new Action(this .action) {
294:
295:                            public void run() {
296:                                delegate.run(this );
297:                            }
298:                        };
299:                        proxy.run();
300:                    } else
301:                        // we could not create the class.
302:                        return false;
303:                    // ran action successfully. Now set intro intro standby if needed.
304:                    if (standbyState == null)
305:                        return true;
306:                    return setStandbyState(standbyState);
307:                } catch (Exception e) {
308:                    Log.error("Could not run action: " + className, e); //$NON-NLS-1$
309:                    return false;
310:                }
311:            }
312:
313:            /**
314:             * Executes a serialized <code>ParameterizedCommand</code>. Uses
315:             * {@link ICommandService#deserialize(String)} to convert the <code>command</code> argument
316:             * into the parameterized command.
317:             */
318:            private boolean executeCommand(String command, String standbyState) {
319:                ICommandService commandService = getCommandService();
320:                IHandlerService handlerService = getHandlerService();
321:                if (commandService == null || handlerService == null) {
322:                    Log
323:                            .error(
324:                                    "Could not get ICommandService or IHandlerService while trying to execute: " + command, null); //$NON-NLS-1$
325:                    return false;
326:                }
327:
328:                try {
329:                    ParameterizedCommand pCommand = commandService
330:                            .deserialize(command);
331:                    pCommand.executeWithChecks(null, handlerService
332:                            .getCurrentState());
333:
334:                    // Executed command successfully. Now set intro standby if needed.
335:                    if (standbyState == null)
336:                        return true;
337:                    return setStandbyState(standbyState);
338:                } catch (CommandException ex) {
339:                    Log.error("Could not execute command: " + command, ex); //$NON-NLS-1$
340:                    return false;
341:                }
342:            }
343:
344:            private ICommandService getCommandService() {
345:                IWorkbench wb = PlatformUI.getWorkbench();
346:                if (wb != null) {
347:                    Object serviceObject = wb.getAdapter(ICommandService.class);
348:                    if (serviceObject != null) {
349:                        ICommandService service = (ICommandService) serviceObject;
350:                        return service;
351:                    }
352:                }
353:                return null;
354:            }
355:
356:            private IHandlerService getHandlerService() {
357:                IWorkbench wb = PlatformUI.getWorkbench();
358:                if (wb != null) {
359:                    Object serviceObject = wb.getAdapter(IHandlerService.class);
360:                    if (serviceObject != null) {
361:                        IHandlerService service = (IHandlerService) serviceObject;
362:                        return service;
363:                    }
364:                }
365:                return null;
366:            }
367:
368:            /**
369:             * Open a help topic. If embed="true", open the help href as an intro page.
370:             * If false, open the href in the Help system window. If embedTarget is set,
371:             * then the Help System topic is embedded instead of the content of the
372:             * specified div.<br>
373:             * In the case of SWT presentation, embedd flag is ignored and the topic is
374:             * opened in the Help system window.
375:             */
376:            private boolean showHelpTopic(String href, String embed,
377:                    String embedTarget) {
378:                return new ShowHelpURLHandler(this ).showHelpTopic(href, embed,
379:                        embedTarget);
380:            }
381:
382:            /**
383:             * Open the help system.
384:             */
385:            private boolean showHelp() {
386:                PlatformUI.getWorkbench().getHelpSystem().displayHelp();
387:                return true;
388:            }
389:
390:            /**
391:             * Launch external browser.
392:             */
393:            private boolean openBrowser(String url, String pluginId) {
394:                // no need to decode url because we will create another url from this
395:                // url anyway. Resolve the url just in case we are trying to load a
396:                // plugin relative file.
397:                url = ModelUtil.resolveURL(url, pluginId);
398:                return Util.openBrowser(url);
399:            }
400:
401:            /**
402:             * Show a URL in an intro page. This is the embedded version of the intro
403:             * action openBrowser(). It is useful when trying to show an html file
404:             * relative to another plugin. When the presentation is UI forms
405:             * presentation, this call behaves exactly as the openBrowser intro action.
406:             */
407:
408:            private boolean openURL(String url, String pluginId) {
409:                IntroModelRoot model = IntroPlugin.getDefault()
410:                        .getIntroModelRoot();
411:                String presentationStyle = model.getPresentation()
412:                        .getImplementationKind();
413:
414:                if (presentationStyle
415:                        .equals(IntroPartPresentation.BROWSER_IMPL_KIND)) {
416:                    // HTML presentation
417:                    url = ModelUtil.resolveURL(url, pluginId);
418:                    BrowserIntroPartImplementation impl = (BrowserIntroPartImplementation) IntroPlugin
419:                            .getDefault().getIntroModelRoot().getPresentation()
420:                            .getIntroPartImplementation();
421:                    Browser browser = impl.getBrowser();
422:                    return browser.setUrl(url);
423:                }
424:                {
425:                    // SWT presentation.
426:                    return openBrowser(url, pluginId);
427:                }
428:            }
429:
430:            private boolean showMessage(String message) {
431:                if (message == null)
432:                    return false;
433:                DialogUtil.displayInfoMessage(null, message);
434:                return true;
435:            }
436:
437:            /**
438:             * Display an Intro Page.
439:             * <p>
440:             * INTRO: revisit picking first page.
441:             */
442:            boolean showPage(String pageId, String standbyState) {
443:                // set the current page id in the model. This will triger appropriate
444:                // listener event to the UI. If setting the page in the model fails (ie:
445:                // the page was not found in the current model, look for it in loaded
446:                // models. return false if failed.
447:                // avoid flicker.
448:                CustomizableIntroPart currentIntroPart = (CustomizableIntroPart) IntroPlugin
449:                        .getIntro();
450:                currentIntroPart.getControl().setRedraw(false);
451:
452:                IntroModelRoot modelRoot = IntroPlugin.getDefault()
453:                        .getIntroModelRoot();
454:                boolean success = modelRoot.setCurrentPageId(pageId);
455:                if (!success)
456:                    success = includePageToShow(modelRoot, pageId);
457:
458:                // we turned drawing off. Turn it on again.
459:                currentIntroPart.getControl().setRedraw(true);
460:
461:                if (success) {
462:                    // found page. Set the history
463:                    modelRoot.getPresentation().updateHistory(
464:                            modelRoot.getCurrentPage());
465:                    // ran action successfully. Now set intro intro standby if needed.
466:                    if (standbyState == null)
467:                        return true;
468:                    return setStandbyState(standbyState);
469:                }
470:                // could not find referenced page.
471:                return false;
472:            }
473:
474:            /**
475:             * Finds the target page and includes it in passed model.
476:             * 
477:             * @param pageId
478:             * @return
479:             */
480:            private boolean includePageToShow(IntroModelRoot model,
481:                    String pageId) {
482:                AbstractIntroPage page = findPageToShow(pageId);
483:                if (page == null) {
484:                    Log
485:                            .warning("Could not find an Intro page with id=" + pageId); //$NON-NLS-1$
486:                    return false;
487:                }
488:                // now clone the target page because original model should be kept
489:                // intact. Resolve target page first to resolve its includes
490:                // properly. Insert presentation shared style at the top of the shared
491:                // styles list because once reparented, the shared style is lost.
492:                // Finally, add clone page to current model.
493:                page.getChildren();
494:                // current kind.
495:                String currentPresentationKind = model.getPresentation()
496:                        .getImplementationKind();
497:                // load shared style corresponding to same presentation kind from target
498:                // model.
499:                IntroPartPresentation targetPresentation = ((IntroModelRoot) page
500:                        .getParent()).getPresentation();
501:                String targetSharedStyle = targetPresentation
502:                        .getSharedStyle(currentPresentationKind);
503:                // clone.
504:                AbstractIntroPage clonedPage = null;
505:                try {
506:                    clonedPage = (AbstractIntroPage) page.clone();
507:                } catch (CloneNotSupportedException ex) {
508:                    // should never be here.
509:                    Log.error("Failed to clone Intro model node.", ex); //$NON-NLS-1$
510:                    return false;
511:                }
512:                // reparent cloned target to current model.
513:                clonedPage.setParent(model);
514:                // REVISIT: SWT presentation does not support multiple shared
515:                // styles.
516:                if (targetSharedStyle != null)
517:                    // add target model shared style.
518:                    clonedPage.insertStyle(targetSharedStyle, 0);
519:                model.addChild(clonedPage);
520:                return model.setCurrentPageId(clonedPage.getId());
521:            }
522:
523:            /**
524:             * Searches all loaded models for the first page with the given id.
525:             * 
526:             * @param pageId
527:             * @return
528:             */
529:            private AbstractIntroPage findPageToShow(String pageId) {
530:                // get all cached models.
531:                Hashtable models = ExtensionPointManager.getInst()
532:                        .getIntroModels();
533:                Enumeration values = models.elements();
534:                while (values.hasMoreElements()) {
535:                    IntroModelRoot model = (IntroModelRoot) values
536:                            .nextElement();
537:                    AbstractIntroPage page = (AbstractIntroPage) model
538:                            .findChild(pageId,
539:                                    AbstractIntroElement.ABSTRACT_PAGE);
540:                    if (page != null)
541:                        return page;
542:                }
543:                // could not find page in any model.
544:                return null;
545:            }
546:
547:            /**
548:             * Navigate foward in the presentation, whichever one it is.
549:             * 
550:             * @return
551:             */
552:            private boolean navigate(String direction) {
553:                // set intro to standby mode. we know we have a customizable part.
554:                CustomizableIntroPart introPart = (CustomizableIntroPart) IntroPlugin
555:                        .getIntro();
556:                if (introPart == null)
557:                    // intro is closed. Do nothing.
558:                    return false;
559:
560:                IntroPartPresentation presentation = (IntroPartPresentation) introPart
561:                        .getAdapter(IntroPartPresentation.class);
562:
563:                if (direction.equalsIgnoreCase(VALUE_BACKWARD))
564:                    return presentation.navigateBackward();
565:                else if (direction.equalsIgnoreCase(VALUE_FORWARD))
566:                    return presentation.navigateForward();
567:                else if (direction.equalsIgnoreCase(VALUE_HOME))
568:                    return presentation.navigateHome();
569:                return false;
570:            }
571:
572:            /**
573:             * @return Returns the action imbedded in this URL.
574:             */
575:            public String getAction() {
576:                return action;
577:            }
578:
579:            /**
580:             * Return a parameter defined in the Intro URL. Returns null if the
581:             * parameter is not defined. If this intro url has a decode=true parameter,
582:             * then all parameters are returned decoded using UTF-8.
583:             * 
584:             * @param parameterId
585:             * @return
586:             */
587:            public String getParameter(String parameterId) {
588:                // make sure to decode only on return, since we may need to recreate the
589:                // url when handling custom urls.
590:                String value = parameters.getProperty(parameterId);
591:                String decode = parameters.getProperty(KEY_DECODE);
592:
593:                if (value != null)
594:                    try {
595:                        if (decode != null
596:                                && decode.equalsIgnoreCase(VALUE_TRUE))
597:                            // we are told to decode the parameters of the url through
598:                            // the decode parameter. Assume that parameters are
599:                            // UTF-8 encoded.
600:                            return StringUtil.decode(value, "UTF-8"); //$NON-NLS-1$
601:                        return value;
602:                    } catch (Exception e) {
603:                        // should never be here.
604:                        Log.error("Failed to decode URL: " + parameterId, e); //$NON-NLS-1$
605:                    }
606:                return value;
607:            }
608:
609:            private boolean handleCustomAction() {
610:                IntroURLAction command = ExtensionPointManager.getInst()
611:                        .getSharedConfigExtensionsManager().getCommand(action);
612:                if (command == null) {
613:                    String message = Messages.IntroURL_badCommand;
614:                    DialogUtil.displayInfoMessage(null, message,
615:                            new Object[] { action });
616:                    return false;
617:                }
618:
619:                // custom command. execute it.
620:                StringBuffer url = new StringBuffer();
621:                url.append("http://org.eclipse.ui.intro/"); //$NON-NLS-1$
622:                url.append(command.getReplaceValue().trim());
623:                if (command.getReplaceValue().indexOf("?") == -1) //$NON-NLS-1$
624:                    // command does not have parameters.
625:                    url.append("?"); //$NON-NLS-1$
626:                else
627:                    // command already has parameters.
628:                    url.append("&"); //$NON-NLS-1$
629:                url.append(retrieveInitialQuery());
630:                IIntroURL introURL = IntroURLFactory.createIntroURL(url
631:                        .toString());
632:                if (introURL != null)
633:                    return introURL.execute();
634:                return false;
635:            }
636:
637:            /**
638:             * Recreate the initial query passed to this URL.
639:             * 
640:             * @return
641:             */
642:            private String retrieveInitialQuery() {
643:                StringBuffer query = new StringBuffer();
644:                Enumeration keys = parameters.keys();
645:                while (keys.hasMoreElements()) {
646:                    String key = (String) keys.nextElement();
647:                    query.append(key);
648:                    query.append("="); //$NON-NLS-1$
649:                    query.append(parameters.get(key));
650:                    if (keys.hasMoreElements())
651:                        query.append("&"); //$NON-NLS-1$
652:                }
653:                return query.toString();
654:            }
655:
656:            private boolean switchToLaunchBar() {
657:                IIntroPart intro = PlatformUI.getWorkbench().getIntroManager()
658:                        .getIntro();
659:                if (intro == null)
660:                    return false;
661:
662:                CustomizableIntroPart cpart = (CustomizableIntroPart) intro;
663:                IntroModelRoot modelRoot = IntroPlugin.getDefault()
664:                        .getIntroModelRoot();
665:                String pageId = modelRoot.getCurrentPageId();
666:                IntroTheme theme = modelRoot.getTheme();
667:                Rectangle bounds = cpart.getControl().getBounds();
668:                Rectangle startBounds = Geometry.toDisplay(cpart.getControl()
669:                        .getParent(), bounds);
670:                closeIntro();
671:
672:                IWorkbenchWindow window = PlatformUI.getWorkbench()
673:                        .getActiveWorkbenchWindow();
674:                IntroLaunchBarElement launchBarElement = modelRoot
675:                        .getPresentation().getLaunchBarElement();
676:                if (launchBarElement == null)
677:                    return true;
678:                IntroLaunchBar launchBar = new IntroLaunchBar(launchBarElement
679:                        .getOrientation(), pageId, launchBarElement, theme);
680:                launchBar.createInActiveWindow();
681:                Rectangle endBounds = Geometry.toDisplay(launchBar.getControl()
682:                        .getParent(), launchBar.getControl().getBounds());
683:
684:                RectangleAnimation animation = new RectangleAnimation(window
685:                        .getShell(), startBounds, endBounds);
686:                animation.schedule();
687:                return true;
688:            }
689:        }
w__w__w__.j_a__v_a_2___s.__c__o__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.