1 11 package org.eclipse.ui.internal; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.jface.resource.ImageDescriptor; 18 import org.eclipse.jface.window.WindowManager; 19 import org.eclipse.ui.IMemento; 20 import org.eclipse.ui.IWorkbench; 21 import org.eclipse.ui.IWorkbenchWindow; 22 import org.eclipse.ui.PlatformUI; 23 import org.eclipse.ui.WorkbenchException; 24 import org.eclipse.ui.application.IWorkbenchConfigurer; 25 import org.eclipse.ui.application.IWorkbenchWindowConfigurer; 26 import org.eclipse.ui.application.WorkbenchAdvisor; 27 28 40 public final class WorkbenchConfigurer implements IWorkbenchConfigurer { 41 42 47 private Map extraData = new HashMap (); 48 49 53 private boolean saveAndRestore = false; 54 55 59 private boolean isEmergencyClosing = false; 60 61 69 private boolean exitOnLastWindowClose = true; 70 71 78 WorkbenchConfigurer() { 79 super(); 80 } 81 82 85 public IWorkbench getWorkbench() { 86 return PlatformUI.getWorkbench(); 87 } 88 89 92 public WindowManager getWorkbenchWindowManager() { 93 return ((Workbench) getWorkbench()).getWindowManager(); 95 } 96 97 100 public void declareImage(String symbolicName, ImageDescriptor descriptor, 101 boolean shared) { 102 if (symbolicName == null || descriptor == null) { 103 throw new IllegalArgumentException (); 104 } 105 WorkbenchImages.declareImage(symbolicName, descriptor, shared); 106 } 107 108 111 public IWorkbenchWindowConfigurer getWindowConfigurer( 112 IWorkbenchWindow window) { 113 if (window == null) { 114 throw new IllegalArgumentException (); 115 } 116 return ((WorkbenchWindow) window).getWindowConfigurer(); 117 } 118 119 122 public boolean getSaveAndRestore() { 123 return saveAndRestore; 124 } 125 126 129 public void setSaveAndRestore(boolean enabled) { 130 saveAndRestore = enabled; 131 } 132 133 136 public Object getData(String key) { 137 if (key == null) { 138 throw new IllegalArgumentException (); 139 } 140 return extraData.get(key); 141 } 142 143 146 public void setData(String key, Object data) { 147 if (key == null) { 148 throw new IllegalArgumentException (); 149 } 150 if (data != null) { 151 extraData.put(key, data); 152 } else { 153 extraData.remove(key); 154 } 155 } 156 157 160 public void emergencyClose() { 161 if (!isEmergencyClosing) { 162 isEmergencyClosing = true; 163 if (Workbench.getInstance() != null 164 && !Workbench.getInstance().isClosing()) { 165 Workbench.getInstance().close( 166 PlatformUI.RETURN_EMERGENCY_CLOSE, true); 167 } 168 } 169 170 } 171 172 175 public boolean emergencyClosing() { 176 return isEmergencyClosing; 177 } 178 179 182 public IStatus restoreState() { 183 return ((Workbench) getWorkbench()).restoreState(); 184 } 185 186 189 public void openFirstTimeWindow() { 190 ((Workbench) getWorkbench()).openFirstTimeWindow(); 191 } 192 193 196 public IWorkbenchWindowConfigurer restoreWorkbenchWindow(IMemento memento) throws WorkbenchException { 197 return getWindowConfigurer(((Workbench) getWorkbench()).restoreWorkbenchWindow(memento)); 198 } 199 200 203 public boolean getExitOnLastWindowClose() { 204 return exitOnLastWindowClose; 205 } 206 207 210 public void setExitOnLastWindowClose(boolean enabled) { 211 exitOnLastWindowClose = enabled; 212 } 213 } 214 | Popular Tags |