|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008 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.about; |
| 13 |
|
| 14 |
import org.eclipse.core.runtime.CoreException; |
| 15 |
import org.eclipse.core.runtime.IConfigurationElement; |
| 16 |
import org.eclipse.core.runtime.IExtensionPoint; |
| 17 |
import org.eclipse.core.runtime.Platform; |
| 18 |
import org.eclipse.jface.action.ContributionManager; |
| 19 |
import org.eclipse.jface.action.IContributionItem; |
| 20 |
import org.eclipse.jface.action.ToolBarManager; |
| 21 |
import org.eclipse.jface.dialogs.Dialog; |
| 22 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 23 |
import org.eclipse.jface.resource.ColorRegistry; |
| 24 |
import org.eclipse.jface.resource.JFaceResources; |
| 25 |
import org.eclipse.swt.SWT; |
| 26 |
import org.eclipse.swt.custom.CTabFolder; |
| 27 |
import org.eclipse.swt.custom.CTabItem; |
| 28 |
import org.eclipse.swt.events.DisposeEvent; |
| 29 |
import org.eclipse.swt.events.DisposeListener; |
| 30 |
import org.eclipse.swt.events.SelectionAdapter; |
| 31 |
import org.eclipse.swt.events.SelectionEvent; |
| 32 |
import org.eclipse.swt.graphics.Color; |
| 33 |
import org.eclipse.swt.layout.FillLayout; |
| 34 |
import org.eclipse.swt.layout.GridData; |
| 35 |
import org.eclipse.swt.layout.GridLayout; |
| 36 |
import org.eclipse.swt.widgets.Composite; |
| 37 |
import org.eclipse.swt.widgets.Control; |
| 38 |
import org.eclipse.swt.widgets.Label; |
| 39 |
import org.eclipse.swt.widgets.Shell; |
| 40 |
import org.eclipse.swt.widgets.ToolBar; |
| 41 |
import org.eclipse.ui.IWorkbenchPreferenceConstants; |
| 42 |
import org.eclipse.ui.PlatformUI; |
| 43 |
import org.eclipse.ui.about.IInstallationPageContainer; |
| 44 |
import org.eclipse.ui.about.InstallationPage; |
| 45 |
import org.eclipse.ui.internal.IWorkbenchThemeConstants; |
| 46 |
import org.eclipse.ui.internal.menus.InternalMenuService; |
| 47 |
import org.eclipse.ui.internal.menus.SlaveMenuService; |
| 48 |
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; |
| 49 |
import org.eclipse.ui.menus.IMenuService; |
| 50 |
import org.eclipse.ui.services.IServiceLocator; |
| 51 |
|
| 52 |
/** |
| 53 |
* @since 3.5 |
| 54 |
* |
| 55 |
*/ |
| 56 |
public class InstallationDialog extends Dialog { |
| 57 |
private static final String ID = "ID"; //$NON-NLS-1$ |
| 58 |
|
| 59 |
private CTabFolder folder; |
| 60 |
private IServiceLocator serviceLocator; |
| 61 |
private ToolBarManager toolbarManager; |
| 62 |
private ButtonManager buttonManager; |
| 63 |
private IMenuService menuService = null; |
| 64 |
|
| 65 |
/** |
| 66 |
* @param parentShell |
| 67 |
*/ |
| 68 |
protected InstallationDialog(Shell parentShell, IServiceLocator locator) { |
| 69 |
super(parentShell); |
| 70 |
this.serviceLocator = locator; |
| 71 |
menuService = new SlaveMenuService((InternalMenuService) serviceLocator |
| 72 |
.getService(IMenuService.class), serviceLocator, null); |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
/* |
| 77 |
* (non-Javadoc) |
| 78 |
* |
| 79 |
* @see |
| 80 |
* org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets |
| 81 |
* .Shell) |
| 82 |
*/ |
| 83 |
protected void configureShell(Shell newShell) { |
| 84 |
super.configureShell(newShell); |
| 85 |
newShell.setSize(600, 768); |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
/* |
| 90 |
* (non-Javadoc) |
| 91 |
* |
| 92 |
* @see |
| 93 |
* org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets |
| 94 |
* .Composite) |
| 95 |
*/ |
| 96 |
protected Control createDialogArea(Composite parent) { |
| 97 |
Composite composite = (Composite) super.createDialogArea(parent); |
| 98 |
|
| 99 |
createToolbar(composite); |
| 100 |
|
| 101 |
folder = new CTabFolder(composite, SWT.MULTI | SWT.BORDER); |
| 102 |
configureFolder(); |
| 103 |
GridData folderData = new GridData(SWT.FILL, SWT.FILL, true, true); |
| 104 |
folderData.widthHint = SWT.DEFAULT; |
| 105 |
folderData.heightHint = SWT.DEFAULT; |
| 106 |
folder.setLayoutData(folderData); |
| 107 |
|
| 108 |
IConfigurationElement[] elements = loadElements(); |
| 109 |
for (int i = 0; i < elements.length; i++) { |
| 110 |
IConfigurationElement element = elements[i]; |
| 111 |
CTabItem item = new CTabItem(folder, SWT.NONE); |
| 112 |
item.setText(element |
| 113 |
.getAttribute(IWorkbenchRegistryConstants.ATT_NAME)); |
| 114 |
item.setData(element); |
| 115 |
Composite control = new Composite(folder, SWT.BORDER); |
| 116 |
control.setLayout(new FillLayout()); |
| 117 |
item.setControl(control); |
| 118 |
|
| 119 |
} |
| 120 |
folder.addSelectionListener(createFolderSelectionListener()); |
| 121 |
return composite; |
| 122 |
} |
| 123 |
|
| 124 |
private SelectionAdapter createFolderSelectionListener() { |
| 125 |
return new SelectionAdapter() { |
| 126 |
|
| 127 |
public void widgetSelected(SelectionEvent e) { |
| 128 |
final CTabItem item = (CTabItem) e.item; |
| 129 |
String id = null; |
| 130 |
if (item.getData() instanceof IConfigurationElement) { |
| 131 |
final IConfigurationElement element = (IConfigurationElement) item |
| 132 |
.getData(); |
| 133 |
|
| 134 |
id = element |
| 135 |
.getAttribute(IWorkbenchRegistryConstants.ATT_ID); |
| 136 |
item.setData(ID, id); |
| 137 |
|
| 138 |
Composite pageComposite = (Composite) item.getControl(); |
| 139 |
try { |
| 140 |
final InstallationPage page = (InstallationPage) element |
| 141 |
.createExecutableExtension(IWorkbenchRegistryConstants.ATT_CLASS); |
| 142 |
page.createControl(pageComposite); |
| 143 |
page.init(createDialogServiceLocator(item)); |
| 144 |
item.setData(page); |
| 145 |
item.addDisposeListener(new DisposeListener() { |
| 146 |
|
| 147 |
public void widgetDisposed(DisposeEvent e) { |
| 148 |
page.dispose(); |
| 149 |
} |
| 150 |
}); |
| 151 |
pageComposite.layout(true, true); |
| 152 |
|
| 153 |
} catch (CoreException e1) { |
| 154 |
Label label = new Label(pageComposite, SWT.NONE); |
| 155 |
label.setText(e1.getMessage()); |
| 156 |
item.setData(null); |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
} else { |
| 161 |
id = (String) item.getData(ID); |
| 162 |
} |
| 163 |
|
| 164 |
menuService.releaseContributions(toolbarManager); |
| 165 |
menuService.populateContributionManager(toolbarManager, |
| 166 |
InstallationDialog.this.getToolbarURI(id)); |
| 167 |
toolbarManager.update(true); |
| 168 |
|
| 169 |
menuService.releaseContributions(buttonManager); |
| 170 |
menuService.populateContributionManager(buttonManager, |
| 171 |
InstallationDialog.this.getButtonBarURI(id)); |
| 172 |
buttonManager.update(true); |
| 173 |
createButton(buttonManager.getParent(), IDialogConstants.OK_ID, |
| 174 |
IDialogConstants.OK_LABEL, true); |
| 175 |
buttonManager.getParent().layout(); |
| 176 |
|
| 177 |
} |
| 178 |
}; |
| 179 |
} |
| 180 |
|
| 181 |
private void createToolbar(Composite composite) { |
| 182 |
toolbarManager = new ToolBarManager(SWT.BORDER); |
| 183 |
toolbarManager.createControl(composite); |
| 184 |
ToolBar toolbar = toolbarManager.getControl(); |
| 185 |
{ |
| 186 |
GridData toolbarData = new GridData(SWT.FILL, SWT.FILL, true, false); |
| 187 |
toolbarData.widthHint = SWT.DEFAULT; |
| 188 |
toolbarData.heightHint = SWT.DEFAULT; |
| 189 |
toolbar.setLayoutData(toolbarData); |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
/* |
| 194 |
* (non-Javadoc) |
| 195 |
* |
| 196 |
* @see |
| 197 |
* org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse |
| 198 |
* .swt.widgets.Composite) |
| 199 |
*/ |
| 200 |
protected void createButtonsForButtonBar(Composite parent) { |
| 201 |
buttonManager = new ButtonManager(parent); |
| 202 |
} |
| 203 |
|
| 204 |
/** |
| 205 |
* @param folder2 |
| 206 |
*/ |
| 207 |
private void configureFolder() { |
| 208 |
ColorRegistry reg = JFaceResources.getColorRegistry(); |
| 209 |
Color c1 = reg.get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_START), c2 = reg |
| 210 |
.get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_END); |
| 211 |
folder.setSelectionBackground(new Color[] { c1, c2 }, new int[] { 50 }, |
| 212 |
true); |
| 213 |
folder.setSelectionForeground(reg |
| 214 |
.get(IWorkbenchThemeConstants.ACTIVE_TAB_TEXT_COLOR)); |
| 215 |
folder.setSimple(PlatformUI.getPreferenceStore().getBoolean( |
| 216 |
IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS)); |
| 217 |
|
| 218 |
} |
| 219 |
|
| 220 |
/** |
| 221 |
* @return |
| 222 |
*/ |
| 223 |
private IConfigurationElement[] loadElements() { |
| 224 |
IExtensionPoint point = Platform.getExtensionRegistry() |
| 225 |
.getExtensionPoint("org.eclipse.ui", "installationPages"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 226 |
return point.getConfigurationElements(); |
| 227 |
} |
| 228 |
|
| 229 |
private String getButtonBarURI(String id) { |
| 230 |
return "toolbar:org.eclipse.ui.installationDialog.buttonbar/" + id; //$NON-NLS-1$ |
| 231 |
} |
| 232 |
|
| 233 |
protected String getToolbarURI(String id) { |
| 234 |
return "toolbar:org.eclipse.ui.installationDialog/" + id; //$NON-NLS-1$ |
| 235 |
} |
| 236 |
|
| 237 |
private IServiceLocator createDialogServiceLocator(final CTabItem item) { |
| 238 |
return new IServiceLocator() { |
| 239 |
|
| 240 |
public Object getService(Class api) { |
| 241 |
if (api == IInstallationPageContainer.class) |
| 242 |
return new IInstallationPageContainer() { |
| 243 |
|
| 244 |
public String getButtonBarURI() { |
| 245 |
return InstallationDialog.this |
| 246 |
.getButtonBarURI((String) item.getData(ID)); |
| 247 |
} |
| 248 |
|
| 249 |
public String getToolbarURI() { |
| 250 |
return InstallationDialog.this |
| 251 |
.getToolbarURI((String) item.getData(ID)); |
| 252 |
} |
| 253 |
|
| 254 |
public void updateMessage() { |
| 255 |
// TBD |
| 256 |
|
| 257 |
} |
| 258 |
}; |
| 259 |
else if (api == IMenuService.class) { |
| 260 |
return menuService; |
| 261 |
} |
| 262 |
return serviceLocator.getService(api); |
| 263 |
} |
| 264 |
|
| 265 |
public boolean hasService(Class api) { |
| 266 |
if (api == IInstallationPageContainer.class) |
| 267 |
return true; |
| 268 |
return serviceLocator.hasService(api); |
| 269 |
} |
| 270 |
}; |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
class ButtonManager extends ContributionManager { |
| 275 |
|
| 276 |
private Composite composite; |
| 277 |
|
| 278 |
/** |
| 279 |
* |
| 280 |
*/ |
| 281 |
public ButtonManager(Composite composite) { |
| 282 |
this.composite = composite; |
| 283 |
} |
| 284 |
|
| 285 |
/** |
| 286 |
* @return |
| 287 |
*/ |
| 288 |
public Composite getParent() { |
| 289 |
return composite; |
| 290 |
} |
| 291 |
|
| 292 |
/* |
| 293 |
* (non-Javadoc) |
| 294 |
* |
| 295 |
* @see org.eclipse.jface.action.IContributionManager#update(boolean) |
| 296 |
*/ |
| 297 |
public void update(boolean force) { |
| 298 |
IContributionItem[] items = getItems(); |
| 299 |
Control[] children = composite.getChildren(); |
| 300 |
|
| 301 |
int visibleChildren = 0; |
| 302 |
for (int i = 0; i < children.length; i++) { |
| 303 |
Control control = children[i]; |
| 304 |
control.dispose(); |
| 305 |
} |
| 306 |
|
| 307 |
for (int i = 0; i < items.length; i++) { |
| 308 |
IContributionItem item = items[i]; |
| 309 |
if (item.isVisible()) { |
| 310 |
item.fill(composite); |
| 311 |
visibleChildren++; |
| 312 |
} |
| 313 |
} |
| 314 |
GridLayout compositeLayout = (GridLayout) composite.getLayout(); |
| 315 |
compositeLayout.numColumns = visibleChildren; |
| 316 |
composite.layout(true); |
| 317 |
} |
| 318 |
} |