/******************************************************************************* | |
* Copyright (c) 2004, 2007 Boeing. | |
* 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: | |
* Boeing - initial API and implementation | |
*******************************************************************************/ | |
package org.eclipse.osee.framework.ui.skynet.commandHandlers.branch.commit; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.logging.Level; | |
import org.eclipse.core.commands.Command; | |
import org.eclipse.core.commands.IParameter; | |
import org.eclipse.core.commands.common.NotDefinedException; | |
import org.eclipse.jface.action.IContributionItem; | |
import org.eclipse.jface.viewers.ISelectionProvider; | |
import org.eclipse.jface.viewers.IStructuredSelection; | |
import org.eclipse.osee.framework.db.connection.exception.OseeCoreException; | |
import org.eclipse.osee.framework.logging.OseeLog; | |
import org.eclipse.osee.framework.skynet.core.artifact.Branch; | |
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager; | |
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench; | |
import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin; | |
import org.eclipse.osee.framework.ui.skynet.commandHandlers.Handlers; | |
import org.eclipse.osee.framework.ui.skynet.commandHandlers.merge.BranchIdParameter; | |
import org.eclipse.osee.framework.ui.skynet.widgets.xBranch.BranchView; | |
import org.eclipse.swt.SWT; | |
import org.eclipse.ui.PlatformUI; | |
import org.eclipse.ui.actions.CompoundContributionItem; | |
import org.eclipse.ui.commands.ICommandService; | |
import org.eclipse.ui.menus.CommandContributionItem; | |
import org.eclipse.ui.menus.CommandContributionItemParameter; | |
/** | |
* @author Jeff C. Phillips | |
*/ | |
public class CommitIntoCompoundContributionItem extends CompoundContributionItem { | |
private static final IParameter[] BRANCH_COMMIT_PARAMETER_DEF = | |
new IParameter[] {new BranchIdParameter(), new CommitBranchParameter()}; | |
private ICommandService commandService; | |
public CommitIntoCompoundContributionItem() { | |
this.commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); | |
} | |
public CommitIntoCompoundContributionItem(String id) { | |
super(id); | |
} | |
/* (non-Javadoc) | |
* @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems() | |
*/ | |
@Override | |
protected IContributionItem[] getContributionItems() { | |
ISelectionProvider selectionProvider = | |
AWorkbench.getActivePage().getActivePart().getSite().getSelectionProvider(); | |
ArrayList<IContributionItem> contributionItems = new ArrayList<IContributionItem>(40); | |
if (selectionProvider != null && selectionProvider.getSelection() instanceof IStructuredSelection) { | |
IStructuredSelection structuredSelection = (IStructuredSelection) selectionProvider.getSelection(); | |
List<Branch> branches = Handlers.getBranchesFromStructuredSelection(structuredSelection); | |
if (!branches.isEmpty()) { | |
Branch selectedBranch = branches.iterator().next(); | |
if (selectedBranch != null) { | |
try { | |
String commandId = "org.eclipse.osee.framework.ui.skynet.branch.BranchView.commitInto"; | |
Command command = configCommandParameter(commandId); | |
CommandContributionItem contributionItem = null; | |
for (Branch branch : BranchManager.getNormalBranches()) { | |
if (!branch.equals(selectedBranch)) { | |
contributionItem = createCommand(branch, commandId); | |
if (command != null && command.isEnabled()) { | |
contributionItems.add(contributionItem); | |
} | |
} | |
} | |
} catch (OseeCoreException ex) { | |
OseeLog.log(SkynetGuiPlugin.class, Level.SEVERE, ex); | |
} | |
} | |
} | |
} | |
return contributionItems.toArray(new IContributionItem[0]); | |
} | |
private CommandContributionItem createCommand(Branch branch, String commandId) throws OseeCoreException { | |
Map<String, String> parameters = new HashMap<String, String>(); | |
parameters.put(BranchView.BRANCH_ID, String.valueOf(branch.getBranchId())); | |
parameters.put(CommitBranchParameter.ARCHIVE_PARENT_BRANCH, "false"); | |
CommandContributionItem contributionItem; | |
String label = branch.getBranchName(); | |
contributionItem = | |
new CommandContributionItem(new CommandContributionItemParameter( | |
PlatformUI.getWorkbench().getActiveWorkbenchWindow(), label, commandId, parameters, null, null, null, | |
label, null, null, SWT.NONE, null, false)); | |
return contributionItem; | |
} | |
private Command configCommandParameter(String commandId) { | |
Command command = commandService.getCommand(commandId); | |
try { | |
command.define(command.getName(), "", commandService.getCategory("org.eclipse.debug.ui.category.run"), | |
BRANCH_COMMIT_PARAMETER_DEF); | |
} catch (NotDefinedException ex) { | |
OseeLog.log(SkynetGuiPlugin.class, Level.SEVERE, ex); | |
} | |
return command; | |
} | |
} |