KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 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 package org.eclipse.ui.internal.intro.impl.model;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.runtime.IConfigurationElement;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.ui.IWorkbenchPreferenceConstants;
19 import org.eclipse.ui.PlatformUI;
20 import org.eclipse.ui.internal.intro.impl.util.ImageUtil;
21 import org.eclipse.ui.intro.config.IntroConfigurer;
22 import org.eclipse.ui.intro.config.IntroElement;
23
24 /**
25  * An Intro Config component captures launch bar information. It can have
26  * shortcuts and one handle. <br>
27  * ps: Handles are not modeled in a dedicated class, but are handled here.
28  *
29  * @since 3.1
30  */

31 public class IntroLaunchBarElement extends AbstractIntroElement {
32     private ArrayList JavaDoc shortcuts;
33
34     IntroLaunchBarElement(IConfigurationElement element) {
35         super(element);
36     }
37
38
39     /**
40      * Returns LAUNCH_BAR.
41      */

42     public int getType() {
43         return AbstractIntroElement.LAUNCH_BAR;
44     }
45
46     /**
47      * Returns the desired launch bar orientation that results from the desired
48      * location. Valid values are <code>SWT.VERTICAL</code> and
49      * <code>SWT.HORIZONTAL</code>.
50      *
51      * @return
52      */

53     public int getOrientation() {
54         int location = getLocation();
55         return (location == SWT.RIGHT || location == SWT.LEFT) ? SWT.VERTICAL
56                 : SWT.HORIZONTAL;
57     }
58
59     /**
60      * Returns the location of the launch bar in the workbench window. Valid
61      * values are <code>SWT.RIGHT</code>,<code>SWT.LEFT</code> and
62      * <code>SWT.BOTTOM</code>.
63      *
64      * @return
65      */

66     public int getLocation() {
67         String JavaDoc location = getCfgElement().getAttribute("location"); //$NON-NLS-1$
68

69         if (location != null) {
70             if (location.equals("left")) //$NON-NLS-1$
71
return SWT.LEFT;
72             if (location.equals("bottom")) //$NON-NLS-1$
73
return SWT.BOTTOM;
74             if (location.equals("right")) //$NON-NLS-1$
75
return SWT.RIGHT;
76         }
77         // default to the initial fast view location
78
String JavaDoc fastviewLocation = PlatformUI.getPreferenceStore().getString(
79             IWorkbenchPreferenceConstants.INITIAL_FAST_VIEW_BAR_LOCATION);
80         if (fastviewLocation.equals(IWorkbenchPreferenceConstants.LEFT))
81             return SWT.LEFT;
82         if (fastviewLocation.equals(IWorkbenchPreferenceConstants.RIGHT))
83             return SWT.RIGHT;
84         if (fastviewLocation.equals(IWorkbenchPreferenceConstants.BOTTOM))
85             return SWT.BOTTOM;
86         // just in case
87
return SWT.RIGHT;
88     }
89
90     public String JavaDoc getBackground() {
91         return getCfgElement().getAttribute("bg"); //$NON-NLS-1$
92
}
93
94     public String JavaDoc getForeground() {
95         return getCfgElement().getAttribute("fg"); //$NON-NLS-1$
96
}
97
98     public boolean getCreateHandle() {
99         return getHandleElement() != null;
100     }
101
102     public boolean getClose() {
103         IConfigurationElement handle = getHandleElement();
104         if (handle != null) {
105             String JavaDoc value = handle.getAttribute("close"); //$NON-NLS-1$
106
return value == null || value.equals("true"); //$NON-NLS-1$
107
}
108         return true;
109     }
110
111     /**
112      * Returns the relative icon path of the handle image.
113      *
114      * @return
115      */

116     private String JavaDoc getHandleImage() {
117         IConfigurationElement handle = getHandleElement();
118         if (handle == null)
119             return null;
120         return handle.getAttribute("image"); //$NON-NLS-1$
121
}
122
123     /**
124      * Returns the icon image of the handle, or <code>null</code> if not
125      * defined or found.
126      *
127      * @return
128      */

129     public ImageDescriptor getHandleImageDescriptor() {
130         String JavaDoc path = getHandleImage();
131         if (path == null)
132             return null;
133         return ImageUtil.createImageDescriptor(getBundle(), path);
134     }
135
136     private IConfigurationElement getHandleElement() {
137         IConfigurationElement[] children = getCfgElement().getChildren(
138             "handle"); //$NON-NLS-1$
139
if (children.length > 0)
140             return children[0];
141         return null;
142     }
143
144     /**
145      * Returns an array of shorcut elements.
146      *
147      * @return
148      */

149     public IntroLaunchBarShortcut[] getShortcuts() {
150         if (shortcuts == null) {
151             createShortcuts();
152         }
153         return (IntroLaunchBarShortcut[]) shortcuts
154             .toArray(new IntroLaunchBarShortcut[shortcuts.size()]);
155     }
156
157     /**
158      * Creates an array of shortcut elements
159      *
160      */

161     private void createShortcuts() {
162         shortcuts = new ArrayList JavaDoc();
163         IntroModelRoot model = getModelRoot();
164         IntroConfigurer configurer = model!=null?model.getConfigurer():null;
165         
166         String JavaDoc cvalue = getCfgElement().getAttribute("computed"); //$NON-NLS-1$
167
boolean computed = cvalue!=null && cvalue.equalsIgnoreCase("true"); //$NON-NLS-1$
168

169         if (computed && configurer!=null) {
170             IntroElement [] children = configurer.getLaunchBarShortcuts();
171             for (int i=0; i<children.length; i++) {
172                 IntroLaunchBarShortcut shortcut = new IntroLaunchBarShortcut(getCfgElement(), children[i]);
173                 shortcuts.add(shortcut);
174             }
175         }
176         else {
177             IConfigurationElement[] children = getCfgElement().getChildren(
178                     IntroLaunchBarShortcut.TAG_SHORTCUT);
179             for (int i = 0; i < children.length; i++) {
180                 IConfigurationElement child = children[i];
181                 IntroLaunchBarShortcut shortcut = new IntroLaunchBarShortcut(child);
182                 shortcuts.add(shortcut);
183             }
184         }
185     }
186 }
187
Popular Tags