| /******************************************************************************* |
| * Copyright (c) 2005, 2009 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| * Ian Bull <irbull@cs.uvic.ca> - bug 204404 and bug 207064 |
| *******************************************************************************/ |
| package org.eclipse.pde.internal.ui.launcher; |
| |
| import java.util.*; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.debug.core.ILaunchConfiguration; |
| import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
| import org.eclipse.pde.core.plugin.IPluginModelBase; |
| import org.eclipse.pde.ui.launcher.BundlesTab; |
| import org.eclipse.pde.ui.launcher.IPDELauncherConstants; |
| |
| public class OSGiBundleBlock extends AbstractPluginBlock { |
| |
| private ILaunchConfiguration fLaunchConfiguration; |
| |
| public OSGiBundleBlock(BundlesTab tab) { |
| super(tab); |
| } |
| |
| protected void savePluginState(ILaunchConfigurationWorkingCopy config) { |
| Object[] selected = fPluginTreeViewer.getCheckedElements(); |
| StringBuffer wBuffer = new StringBuffer(); |
| StringBuffer tBuffer = new StringBuffer(); |
| for (int i = 0; i < selected.length; i++) { |
| if (selected[i] instanceof IPluginModelBase) { |
| IPluginModelBase model = (IPluginModelBase) selected[i]; |
| if (model.getUnderlyingResource() == null) { |
| appendToBuffer(tBuffer, model); |
| } else { |
| appendToBuffer(wBuffer, model); |
| } |
| } |
| } |
| config.setAttribute(IPDELauncherConstants.WORKSPACE_BUNDLES, wBuffer.length() == 0 ? (String) null : wBuffer.toString()); |
| config.setAttribute(IPDELauncherConstants.TARGET_BUNDLES, tBuffer.length() == 0 ? (String) null : tBuffer.toString()); |
| |
| StringBuffer buffer = new StringBuffer(); |
| if (fAddWorkspaceButton.getSelection()) { |
| for (int i = 0; i < fWorkspaceModels.length; i++) { |
| if (!fPluginTreeViewer.getChecked(fWorkspaceModels[i])) { |
| appendToBuffer(buffer, fWorkspaceModels[i]); |
| } |
| } |
| } |
| config.setAttribute(IPDELauncherConstants.DESELECTED_WORKSPACE_PLUGINS, buffer.length() > 0 ? buffer.toString() : (String) null); |
| } |
| |
| public void initializeFrom(ILaunchConfiguration configuration) throws CoreException { |
| super.initializeFrom(configuration); |
| initWorkspacePluginsState(configuration); |
| initExternalPluginsState(configuration); |
| updateCounter(); |
| fLaunchConfiguration = configuration; |
| handleFilterButton(); // Once the page is initialized, apply any filtering. |
| } |
| |
| // TODO deal with the discrepency between save/init states of the two blocks |
| |
| private void initExternalPluginsState(ILaunchConfiguration configuration) throws CoreException { |
| Map map = BundleLauncherHelper.getTargetBundleMap(configuration, Collections.EMPTY_SET, IPDELauncherConstants.TARGET_BUNDLES); |
| Iterator iter = map.keySet().iterator(); |
| fPluginTreeViewer.setSubtreeChecked(fExternalPlugins, false); |
| while (iter.hasNext()) { |
| IPluginModelBase model = (IPluginModelBase) iter.next(); |
| if (fPluginTreeViewer.setChecked(model, true)) { |
| setText(model, map.get(model).toString()); |
| } |
| } |
| fNumExternalChecked = map.size(); |
| resetGroup(fExternalPlugins); |
| fPluginTreeViewer.setChecked(fExternalPlugins, fNumExternalChecked > 0); |
| fPluginTreeViewer.setGrayed(fExternalPlugins, fNumExternalChecked > 0 && fNumExternalChecked < fExternalModels.length); |
| } |
| |
| private void initWorkspacePluginsState(ILaunchConfiguration configuration) throws CoreException { |
| Map map = BundleLauncherHelper.getWorkspaceBundleMap(configuration); |
| Iterator iter = map.keySet().iterator(); |
| fPluginTreeViewer.setSubtreeChecked(fWorkspacePlugins, false); |
| while (iter.hasNext()) { |
| IPluginModelBase model = (IPluginModelBase) iter.next(); |
| if (fPluginTreeViewer.setChecked(model, true)) { |
| setText(model, map.get(model).toString()); |
| } |
| } |
| fNumWorkspaceChecked = map.size(); |
| resetGroup(fWorkspacePlugins); |
| |
| fPluginTreeViewer.setChecked(fWorkspacePlugins, fNumWorkspaceChecked > 0); |
| fPluginTreeViewer.setGrayed(fWorkspacePlugins, fNumWorkspaceChecked > 0 && fNumWorkspaceChecked < fWorkspaceModels.length); |
| } |
| |
| protected LaunchValidationOperation createValidationOperation() { |
| return new OSGiValidationOperation(fLaunchConfiguration); |
| } |
| |
| } |