KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > impl > model > url > IntroURL


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.intro.impl.model.url;
13
14 import java.util.Enumeration JavaDoc;
15 import java.util.Hashtable JavaDoc;
16 import java.util.Properties JavaDoc;
17
18 import org.eclipse.core.commands.ParameterizedCommand;
19 import org.eclipse.core.commands.common.CommandException;
20 import org.eclipse.jface.action.Action;
21 import org.eclipse.jface.action.IAction;
22 import org.eclipse.jface.util.Geometry;
23 import org.eclipse.swt.browser.Browser;
24 import org.eclipse.swt.custom.BusyIndicator;
25 import org.eclipse.swt.graphics.Rectangle;
26 import org.eclipse.swt.widgets.Display;
27 import org.eclipse.ui.IActionDelegate;
28 import org.eclipse.ui.IWorkbench;
29 import org.eclipse.ui.IWorkbenchWindow;
30 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
31 import org.eclipse.ui.PlatformUI;
32 import org.eclipse.ui.commands.ICommandService;
33 import org.eclipse.ui.handlers.IHandlerService;
34 import org.eclipse.ui.internal.RectangleAnimation;
35 import org.eclipse.ui.internal.intro.impl.IIntroConstants;
36 import org.eclipse.ui.internal.intro.impl.IntroPlugin;
37 import org.eclipse.ui.internal.intro.impl.Messages;
38 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroElement;
39 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage;
40 import org.eclipse.ui.internal.intro.impl.model.IntroLaunchBarElement;
41 import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot;
42 import org.eclipse.ui.internal.intro.impl.model.IntroPartPresentation;
43 import org.eclipse.ui.internal.intro.impl.model.IntroTheme;
44 import org.eclipse.ui.internal.intro.impl.model.IntroURLAction;
45 import org.eclipse.ui.internal.intro.impl.model.loader.ExtensionPointManager;
46 import org.eclipse.ui.internal.intro.impl.model.loader.ModelLoaderUtil;
47 import org.eclipse.ui.internal.intro.impl.model.util.ModelUtil;
48 import org.eclipse.ui.internal.intro.impl.parts.StandbyPart;
49 import org.eclipse.ui.internal.intro.impl.presentations.BrowserIntroPartImplementation;
50 import org.eclipse.ui.internal.intro.impl.presentations.IntroLaunchBar;
51 import org.eclipse.ui.internal.intro.impl.util.DialogUtil;
52 import org.eclipse.ui.internal.intro.impl.util.Log;
53 import org.eclipse.ui.internal.intro.impl.util.StringUtil;
54 import org.eclipse.ui.internal.intro.impl.util.Util;
55 import org.eclipse.ui.intro.IIntroPart;
56 import org.eclipse.ui.intro.IIntroSite;
57 import org.eclipse.ui.intro.config.CustomizableIntroPart;
58 import org.eclipse.ui.intro.config.IIntroAction;
59 import org.eclipse.ui.intro.config.IIntroURL;
60 import org.eclipse.ui.intro.config.IntroURLFactory;
61
62 /**
63  * An intro url. An intro URL is a valid http url, with org.eclipse.ui.intro as
64  * a host. This class holds all logic to execute Intro URL commands, ie: an
65  * Intro URL knows how to execute itself.
66  */

67 public class IntroURL implements IIntroURL {
68
69
70     /**
71      * Intro URL constants.
72      */

73     public static final String JavaDoc INTRO_PROTOCOL = "http"; //$NON-NLS-1$
74
public static final String JavaDoc INTRO_HOST_ID = "org.eclipse.ui.intro"; //$NON-NLS-1$
75

76     /**
77      * Constants that represent Intro URL actions.
78      */

79     public static final String JavaDoc SET_STANDBY_MODE = "setStandbyMode"; //$NON-NLS-1$
80
public static final String JavaDoc SHOW_STANDBY = "showStandby"; //$NON-NLS-1$
81
public static final String JavaDoc CLOSE = "close"; //$NON-NLS-1$
82
public static final String JavaDoc SHOW_HELP_TOPIC = "showHelpTopic"; //$NON-NLS-1$
83
public static final String JavaDoc SHOW_HELP = "showHelp"; //$NON-NLS-1$
84
public static final String JavaDoc OPEN_BROWSER = "openBrowser"; //$NON-NLS-1$
85
public static final String JavaDoc OPEN_URL = "openURL"; //$NON-NLS-1$
86
public static final String JavaDoc RUN_ACTION = "runAction"; //$NON-NLS-1$
87
public static final String JavaDoc SHOW_PAGE = "showPage"; //$NON-NLS-1$
88
public static final String JavaDoc SHOW_MESSAGE = "showMessage"; //$NON-NLS-1$
89
public static final String JavaDoc NAVIGATE = "navigate"; //$NON-NLS-1$
90
public static final String JavaDoc SWITCH_TO_LAUNCH_BAR = "switchToLaunchBar"; //$NON-NLS-1$
91
public static final String JavaDoc EXECUTE = "execute"; //$NON-NLS-1$
92

93     /**
94      * Constants that represent valid action keys.
95      */

96     public static final String JavaDoc KEY_ID = "id"; //$NON-NLS-1$
97
public static final String JavaDoc KEY_PLUGIN_ID = "pluginId"; //$NON-NLS-1$
98
public static final String JavaDoc KEY_CLASS = "class"; //$NON-NLS-1$
99
public static final String JavaDoc KEY_STANDBY = "standby"; //$NON-NLS-1$
100
public static final String JavaDoc KEY_PART_ID = "partId"; //$NON-NLS-1$
101
public static final String JavaDoc KEY_INPUT = "input"; //$NON-NLS-1$
102
public static final String JavaDoc KEY_MESSAGE = "message"; //$NON-NLS-1$
103
public static final String JavaDoc KEY_URL = "url"; //$NON-NLS-1$
104
public static final String JavaDoc KEY_DIRECTION = "direction"; //$NON-NLS-1$
105
public static final String JavaDoc KEY_EMBED = "embed"; //$NON-NLS-1$
106
public static final String JavaDoc KEY_EMBED_TARGET = "embedTarget"; //$NON-NLS-1$
107
public static final String JavaDoc KEY_DECODE = "decode"; //$NON-NLS-1$
108
public static final String JavaDoc KEY_COMAND = "command"; //$NON-NLS-1$
109

110
111     public static final String JavaDoc VALUE_BACKWARD = "backward"; //$NON-NLS-1$
112
public static final String JavaDoc VALUE_FORWARD = "forward"; //$NON-NLS-1$
113
public static final String JavaDoc VALUE_HOME = "home"; //$NON-NLS-1$
114
public static final String JavaDoc VALUE_TRUE = "true"; //$NON-NLS-1$
115
public static final String JavaDoc VALUE_FALSE = "false"; //$NON-NLS-1$
116

117
118
119     private String JavaDoc action = null;
120     private Properties JavaDoc parameters = null;
121
122     /**
123      * Prevent creation. Must be created through an IntroURLParser. This
124      * constructor assumed we have a valid intro url.
125      *
126      * @param url
127      */

128     IntroURL(String JavaDoc action, Properties JavaDoc parameters) {
129         this.action = action;
130         this.parameters = parameters;
131     }
132
133     /**
134      * Executes whatever valid Intro action is embedded in this Intro URL.
135      *
136      */

137     public boolean execute() {
138         final boolean[] result = new boolean[1];
139         Display display = Display.getCurrent();
140         
141         BusyIndicator.showWhile(display, new Runnable JavaDoc() {
142
143             public void run() {
144                 result[0] = doExecute();
145             }
146         });
147         return result[0];
148     }
149
150     protected boolean doExecute() {
151         if (Log.logInfo) {
152             String JavaDoc msg = StringUtil.concat("Running Intro URL action ", action, //$NON-NLS-1$
153
" with parameters: ", parameters.toString()).toString(); //$NON-NLS-1$
154
Log.info(msg);
155         }
156
157         // check for all supported Intro actions first.
158
if (action.equals(CLOSE))
159             return closeIntro();
160
161         else if (action.equals(SET_STANDBY_MODE))
162             // Sets the state of the intro part. Does not care about passing
163
// input to the part.
164
return setStandbyState(getParameter(KEY_STANDBY));
165
166         else if (action.equals(SHOW_STANDBY))
167             return handleStandbyState(getParameter(KEY_PART_ID),
168                 getParameter(KEY_INPUT));
169
170         else if (action.equals(SHOW_HELP))
171             // display the full Help System.
172
return showHelp();
173
174         else if (action.equals(SHOW_HELP_TOPIC))
175             // display a Help System Topic. It can be displayed in the Help
176
// system window, or embedded as an intro page.
177
// return showHelpTopic(getParameter(KEY_ID));
178
return showHelpTopic(getParameter(KEY_ID), getParameter(KEY_EMBED),
179                 getParameter(KEY_EMBED_TARGET));
180
181         else if (action.equals(OPEN_BROWSER))
182             // display url in external browser
183
return openBrowser(getParameter(KEY_URL),
184                 getParameter(KEY_PLUGIN_ID));
185
186         if (action.equals(OPEN_URL))
187             // display url embedded in intro browser.
188
return openURL(getParameter(KEY_URL), getParameter(KEY_PLUGIN_ID));
189
190         else if (action.equals(RUN_ACTION))
191             // run an Intro action. Get the pluginId and the class keys. Pass
192
// the parameters and the standby state.
193
return runAction(getParameter(KEY_PLUGIN_ID),
194                 getParameter(KEY_CLASS), parameters, getParameter(KEY_STANDBY));
195         
196         else if (action.equals(EXECUTE))
197             // execute a serialized command
198
return executeCommand(getParameter(KEY_COMAND), getParameter(KEY_STANDBY));
199
200         else if (action.equals(SHOW_PAGE))
201             // display an Intro Page.
202
return showPage(getParameter(KEY_ID), 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
218     private boolean closeIntro() {
219         // Relies on Workbench.
220
return IntroPlugin.closeIntro();
221     }
222
223     /**
224      * Sets the into part to standby, and shows the passed standby part, with
225      * the given input. Forces the Intro view to open, if not yet created.
226      *
227      * @param partId
228      * @param input
229      */

230     private boolean handleStandbyState(String JavaDoc partId, String JavaDoc input) {
231         // set intro to standby mode. we know we have a customizable part.
232
CustomizableIntroPart introPart = (CustomizableIntroPart) IntroPlugin
233             .getIntro();
234         if (introPart == null)
235             introPart = (CustomizableIntroPart) IntroPlugin.showIntro(true);
236         // store the flag to indicate that standbypart is needed.
237
introPart.getControl().setData(IIntroConstants.SHOW_STANDBY_PART,
238             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 JavaDoc 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     /**
270      * Run an action
271      */

272     private boolean runAction(String JavaDoc pluginId, String JavaDoc className,
273             Properties JavaDoc parameters, String JavaDoc standbyState) {
274
275         Object JavaDoc actionObject = ModelLoaderUtil.createClassInstance(pluginId,
276             className);
277         try {
278             if (actionObject instanceof IIntroAction) {
279                 IIntroAction introAction = (IIntroAction) actionObject;
280                 IIntroSite site = IntroPlugin.getDefault().getIntroModelRoot()
281                     .getPresentation().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).init(PlatformUI
291                         .getWorkbench().getActiveWorkbenchWindow());
292                 Action proxy = new Action(this.action) {
293
294                     public void run() {
295                         delegate.run(this);
296                     }
297                 };
298                 proxy.run();
299             } else
300                 // we could not create the class.
301
return false;
302             // ran action successfully. Now set intro intro standby if needed.
303
if (standbyState == null)
304                 return true;
305             return setStandbyState(standbyState);
306         } catch (Exception JavaDoc e) {
307             Log.error("Could not run action: " + className, e); //$NON-NLS-1$
308
return false;
309         }
310     }
311     
312     /**
313      * Executes a serialized <code>ParameterizedCommand</code>. Uses
314      * {@link ICommandService#deserialize(String)} to convert the <code>command</code> argument
315      * into the parameterized command.
316      */

317     private boolean executeCommand(String JavaDoc command, String JavaDoc standbyState) {
318         ICommandService commandService = getCommandService();
319         IHandlerService handlerService = getHandlerService();
320         if (commandService == null || handlerService == null) {
321             Log.error("Could not get ICommandService or IHandlerService while trying to execute: " + command, null); //$NON-NLS-1$
322
return false;
323         }
324
325         try {
326             ParameterizedCommand pCommand = commandService.deserialize(command);
327             pCommand.executeWithChecks(null, handlerService.getCurrentState());
328
329             // Executed command successfully. Now set intro standby if needed.
330
if (standbyState == null)
331                 return true;
332             return setStandbyState(standbyState);
333         } catch (CommandException ex) {
334             Log.error("Could not execute command: " + command, ex); //$NON-NLS-1$
335
return false;
336         }
337     }
338     
339     private ICommandService getCommandService() {
340         IWorkbench wb = PlatformUI.getWorkbench();
341         if (wb != null) {
342             Object JavaDoc serviceObject = wb.getAdapter(ICommandService.class);
343             if (serviceObject != null) {
344                 ICommandService service = (ICommandService)serviceObject;
345                 return service;
346             }
347         }
348         return null;
349     }
350
351     private IHandlerService getHandlerService() {
352         IWorkbench wb = PlatformUI.getWorkbench();
353         if (wb != null) {
354             Object JavaDoc serviceObject = wb.getAdapter(IHandlerService.class);
355             if (serviceObject != null) {
356                 IHandlerService service = (IHandlerService)serviceObject;
357                 return service;
358             }
359         }
360         return null;
361     }
362
363     /**
364      * Open a help topic. If embed="true", open the help href as an intro page.
365      * If false, open the href in the Help system window. If embedTarget is set,
366      * then the Help System topic is embedded instead of the content of the
367      * specified div.<br>
368      * In the case of SWT presentation, embedd flag is ignored and the topic is
369      * opened in the Help system window.
370      */

371     private boolean showHelpTopic(String JavaDoc href, String JavaDoc embed, String JavaDoc embedTarget) {
372         return new ShowHelpURLHandler(this).showHelpTopic(href, embed,
373             embedTarget);
374     }
375
376
377
378     /**
379      * Open the help system.
380      */

381     private boolean showHelp() {
382         PlatformUI.getWorkbench().getHelpSystem().displayHelp();
383         return true;
384     }
385
386     /**
387      * Launch external browser.
388      */

389     private boolean openBrowser(String JavaDoc url, String JavaDoc pluginId) {
390         // no need to decode url because we will create another url from this
391
// url anyway. Resolve the url just in case we are trying to load a
392
// plugin relative file.
393
url = ModelUtil.resolveURL(url, pluginId);
394         return Util.openBrowser(url);
395     }
396
397
398     /**
399      * Show a URL in an intro page. This is the embedded version of the intro
400      * action openBrowser(). It is useful when trying to show an html file
401      * relative to another plugin. When the presentation is UI forms
402      * presentation, this call behaves exactly as the openBrowser intro action.
403      */

404
405     private boolean openURL(String JavaDoc url, String JavaDoc pluginId) {
406         IntroModelRoot model = IntroPlugin.getDefault().getIntroModelRoot();
407         String JavaDoc presentationStyle = model.getPresentation()
408             .getImplementationKind();
409
410         if (presentationStyle.equals(IntroPartPresentation.BROWSER_IMPL_KIND)) {
411             // HTML presentation
412
url = ModelUtil.resolveURL(url, pluginId);
413             BrowserIntroPartImplementation impl = (BrowserIntroPartImplementation) IntroPlugin
414                 .getDefault().getIntroModelRoot().getPresentation()
415                 .getIntroPartImplementation();
416             Browser browser = impl.getBrowser();
417             return browser.setUrl(url);
418         }
419         {
420             // SWT presentation.
421
return openBrowser(url, pluginId);
422         }
423     }
424
425
426     private boolean showMessage(String JavaDoc message) {
427         if (message == null)
428             return false;
429         DialogUtil.displayInfoMessage(null, message);
430         return true;
431     }
432
433     /**
434      * Display an Intro Page.
435      * <p>
436      * INTRO: revisit picking first page.
437      */

438     boolean showPage(String JavaDoc pageId, String JavaDoc standbyState) {
439         // set the current page id in the model. This will triger appropriate
440
// listener event to the UI. If setting the page in the model fails (ie:
441
// the page was not found in the current model, look for it in loaded
442
// models. return false if failed.
443
// avoid flicker.
444
CustomizableIntroPart currentIntroPart = (CustomizableIntroPart) IntroPlugin
445             .getIntro();
446         currentIntroPart.getControl().setRedraw(false);
447
448         IntroModelRoot modelRoot = IntroPlugin.getDefault().getIntroModelRoot();
449         boolean success = modelRoot.setCurrentPageId(pageId);
450         if (!success)
451             success = includePageToShow(modelRoot, pageId);
452
453         // we turned drawing off. Turn it on again.
454
currentIntroPart.getControl().setRedraw(true);
455
456         if (success) {
457             // found page. Set the history
458
modelRoot.getPresentation().updateHistory(
459                 modelRoot.getCurrentPage());
460             // ran action successfully. Now set intro intro standby if needed.
461
if (standbyState == null)
462                 return true;
463             return setStandbyState(standbyState);
464         }
465         // could not find referenced page.
466
return false;
467     }
468
469     /**
470      * Finds the target page and includes it in passed model.
471      *
472      * @param pageId
473      * @return
474      */

475     private boolean includePageToShow(IntroModelRoot model, String JavaDoc pageId) {
476         AbstractIntroPage page = findPageToShow(pageId);
477         if (page == null) {
478             Log.warning("Could not find an Intro page with id=" + pageId); //$NON-NLS-1$
479
return false;
480         }
481         // now clone the target page because original model should be kept
482
// intact. Resolve target page first to resolve its includes
483
// properly. Insert presentation shared style at the top of the shared
484
// styles list because once reparented, the shared style is lost.
485
// Finally, add clone page to current model.
486
page.getChildren();
487         // current kind.
488
String JavaDoc currentPresentationKind = model.getPresentation()
489             .getImplementationKind();
490         // load shared style corresponding to same presentation kind from target
491
// model.
492
IntroPartPresentation targetPresentation = ((IntroModelRoot) page
493             .getParent()).getPresentation();
494         String JavaDoc targetSharedStyle = targetPresentation
495             .getSharedStyle(currentPresentationKind);
496         // clone.
497
AbstractIntroPage clonedPage = null;
498         try {
499             clonedPage = (AbstractIntroPage) page.clone();
500         } catch (CloneNotSupportedException JavaDoc ex) {
501             // should never be here.
502
Log.error("Failed to clone Intro model node.", ex); //$NON-NLS-1$
503
return false;
504         }
505         // reparent cloned target to current model.
506
clonedPage.setParent(model);
507         // REVISIT: SWT presentation does not support multiple shared
508
// styles.
509
if (targetSharedStyle != null)
510             // add target model shared style.
511
clonedPage.insertStyle(targetSharedStyle, 0);
512         model.addChild(clonedPage);
513         return model.setCurrentPageId(clonedPage.getId());
514     }
515
516
517     /**
518      * Searches all loaded models for the first page with the given id.
519      *
520      * @param pageId
521      * @return
522      */

523     private AbstractIntroPage findPageToShow(String JavaDoc pageId) {
524         // get all cached models.
525
Hashtable JavaDoc models = ExtensionPointManager.getInst().getIntroModels();
526         Enumeration JavaDoc values = models.elements();
527         while (values.hasMoreElements()) {
528             IntroModelRoot model = (IntroModelRoot) values.nextElement();
529             AbstractIntroPage page = (AbstractIntroPage) model.findChild(
530                 pageId, AbstractIntroElement.ABSTRACT_PAGE);
531             if (page != null)
532                 return page;
533         }
534         // could not find page in any model.
535
return null;
536     }
537
538     /**
539      * Navigate foward in the presentation, whichever one it is.
540      *
541      * @return
542      */

543     private boolean navigate(String JavaDoc direction) {
544         // set intro to standby mode. we know we have a customizable part.
545
CustomizableIntroPart introPart = (CustomizableIntroPart) IntroPlugin
546             .getIntro();
547         if (introPart == null)
548             // intro is closed. Do nothing.
549
return false;
550
551         IntroPartPresentation presentation = (IntroPartPresentation) introPart
552             .getAdapter(IntroPartPresentation.class);
553
554         if (direction.equalsIgnoreCase(VALUE_BACKWARD))
555             return presentation.navigateBackward();
556         else if (direction.equalsIgnoreCase(VALUE_FORWARD))
557             return presentation.navigateForward();
558         else if (direction.equalsIgnoreCase(VALUE_HOME))
559             return presentation.navigateHome();
560         return false;
561     }
562
563
564     /**
565      * @return Returns the action imbedded in this URL.
566      */

567     public String JavaDoc getAction() {
568         return action;
569     }
570
571     /**
572      * Return a parameter defined in the Intro URL. Returns null if the
573      * parameter is not defined. If this intro url has a decode=true parameter,
574      * then all parameters are returned decoded using UTF-8.
575      *
576      * @param parameterId
577      * @return
578      */

579     public String JavaDoc getParameter(String JavaDoc parameterId) {
580         // make sure to decode only on return, since we may need to recreate the
581
// url when handling custom urls.
582
String JavaDoc value = parameters.getProperty(parameterId);
583         String JavaDoc decode = parameters.getProperty(KEY_DECODE);
584
585         if (value != null)
586             try {
587                 if (decode!=null && decode.equalsIgnoreCase(VALUE_TRUE))
588                     // we are told to decode the parameters of the url through
589
// the decode parameter. Assume that parameters are
590
// UTF-8 encoded.
591
return StringUtil.decode(value, "UTF-8"); //$NON-NLS-1$
592
return value;
593             } catch (Exception JavaDoc e) {
594                 // should never be here.
595
Log.error("Failed to decode URL: " + parameterId, e); //$NON-NLS-1$
596
}
597         return value;
598     }
599
600     private boolean handleCustomAction() {
601         IntroURLAction command = ExtensionPointManager.getInst()
602             .getSharedConfigExtensionsManager().getCommand(action);
603         if (command == null) {
604             String JavaDoc message = Messages.IntroURL_badCommand;
605             DialogUtil.displayInfoMessage(null, message,
606                 new Object JavaDoc[] { action });
607             return false;
608         }
609
610         // custom command. execute it.
611
StringBuffer JavaDoc url = new StringBuffer JavaDoc();
612         url.append("http://org.eclipse.ui.intro/"); //$NON-NLS-1$
613
url.append(command.getReplaceValue().trim());
614         if (command.getReplaceValue().indexOf("?") == -1) //$NON-NLS-1$
615
// command does not have parameters.
616
url.append("?"); //$NON-NLS-1$
617
else
618             // command already has parameters.
619
url.append("&"); //$NON-NLS-1$
620
url.append(retrieveInitialQuery());
621         IIntroURL introURL = IntroURLFactory.createIntroURL(url.toString());
622         if (introURL != null)
623             return introURL.execute();
624         return false;
625     }
626
627
628     /**
629      * Recreate the initial query passed to this URL.
630      *
631      * @return
632      */

633     private String JavaDoc retrieveInitialQuery() {
634         StringBuffer JavaDoc query = new StringBuffer JavaDoc();
635         Enumeration JavaDoc keys = parameters.keys();
636         while (keys.hasMoreElements()) {
637             String JavaDoc key = (String JavaDoc) keys.nextElement();
638             query.append(key);
639             query.append("="); //$NON-NLS-1$
640
query.append(parameters.get(key));
641             if (keys.hasMoreElements())
642                 query.append("&"); //$NON-NLS-1$
643
}
644         return query.toString();
645     }
646
647
648     private boolean switchToLaunchBar() {
649         IIntroPart intro = PlatformUI.getWorkbench().getIntroManager()
650             .getIntro();
651         if (intro == null)
652             return false;
653
654         CustomizableIntroPart cpart = (CustomizableIntroPart) intro;
655         IntroModelRoot modelRoot = IntroPlugin.getDefault().getIntroModelRoot();
656         String JavaDoc pageId = modelRoot.getCurrentPageId();
657         IntroTheme theme = modelRoot.getTheme();
658         Rectangle bounds = cpart.getControl().getBounds();
659         Rectangle startBounds = Geometry.toDisplay(cpart.getControl()
660             .getParent(), bounds);
661         closeIntro();
662
663         IWorkbenchWindow window = PlatformUI.getWorkbench()
664             .getActiveWorkbenchWindow();
665         IntroLaunchBarElement launchBarElement = modelRoot.getPresentation()
666             .getLaunchBarElement();
667         if (launchBarElement==null)
668             return true;
669         IntroLaunchBar launchBar = new IntroLaunchBar(launchBarElement
670             .getOrientation(), pageId, launchBarElement, theme);
671         launchBar.createInActiveWindow();
672         Rectangle endBounds = Geometry.toDisplay(launchBar.getControl()
673             .getParent(), launchBar.getControl().getBounds());
674
675         RectangleAnimation animation = new RectangleAnimation(
676             window.getShell(), startBounds, endBounds);
677         animation.schedule();
678         return true;
679     }
680 }
681
Popular Tags