1 11 package org.eclipse.ui.internal.intro.impl.model; 12 13 import java.util.ArrayList ; 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 31 public class IntroLaunchBarElement extends AbstractIntroElement { 32 private ArrayList shortcuts; 33 34 IntroLaunchBarElement(IConfigurationElement element) { 35 super(element); 36 } 37 38 39 42 public int getType() { 43 return AbstractIntroElement.LAUNCH_BAR; 44 } 45 46 53 public int getOrientation() { 54 int location = getLocation(); 55 return (location == SWT.RIGHT || location == SWT.LEFT) ? SWT.VERTICAL 56 : SWT.HORIZONTAL; 57 } 58 59 66 public int getLocation() { 67 String location = getCfgElement().getAttribute("location"); 69 if (location != null) { 70 if (location.equals("left")) return SWT.LEFT; 72 if (location.equals("bottom")) return SWT.BOTTOM; 74 if (location.equals("right")) return SWT.RIGHT; 76 } 77 String 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 return SWT.RIGHT; 88 } 89 90 public String getBackground() { 91 return getCfgElement().getAttribute("bg"); } 93 94 public String getForeground() { 95 return getCfgElement().getAttribute("fg"); } 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 value = handle.getAttribute("close"); return value == null || value.equals("true"); } 108 return true; 109 } 110 111 116 private String getHandleImage() { 117 IConfigurationElement handle = getHandleElement(); 118 if (handle == null) 119 return null; 120 return handle.getAttribute("image"); } 122 123 129 public ImageDescriptor getHandleImageDescriptor() { 130 String 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"); if (children.length > 0) 140 return children[0]; 141 return null; 142 } 143 144 149 public IntroLaunchBarShortcut[] getShortcuts() { 150 if (shortcuts == null) { 151 createShortcuts(); 152 } 153 return (IntroLaunchBarShortcut[]) shortcuts 154 .toArray(new IntroLaunchBarShortcut[shortcuts.size()]); 155 } 156 157 161 private void createShortcuts() { 162 shortcuts = new ArrayList (); 163 IntroModelRoot model = getModelRoot(); 164 IntroConfigurer configurer = model!=null?model.getConfigurer():null; 165 166 String cvalue = getCfgElement().getAttribute("computed"); boolean computed = cvalue!=null && cvalue.equalsIgnoreCase("true"); 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 |