blob: b2b903231bb62304d8cb22c37c0389e1c3effc70 [file] [log] [blame]
//------------------------------------------------------------------------------
// Copyright (c) 2005, 2006 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 implementation
//------------------------------------------------------------------------------
package org.eclipse.epf.library.edit.ui;
import java.util.List;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.epf.library.edit.LibraryEditResources;
import org.eclipse.epf.library.edit.TngAdapterFactory;
import org.eclipse.epf.library.edit.command.IUserInteractionHandler;
import org.eclipse.epf.library.edit.util.ExtensionManager;
import org.eclipse.epf.uma.Role;
import org.eclipse.epf.uma.TeamProfile;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell;
/**
* UI Dialog class which will ask user to assign a role to team automatically.
*
* @author Shilpa Toraskar
* @since 1.0
*/
public class TeamSelection {
/**
* It shows dialog box all teams. Returns team user selected
*
* @param element
* @return
*/
public static TeamProfile getSelectedTeam(List teamList, Role role, Shell shell) {
// ILabelProvider labelProvider = new AdapterFactoryLabelProvider(
// TngAdapterFactory.INSTANCE.getOBS_ComposedAdapterFactory()) {
// public String getText(Object obj) {
// if (obj instanceof TeamProfile) {
// return ((TeamProfile) obj).getName();
// }
// return ""; //$NON-NLS-1$
// }
// };
// if(shell == null) {
// try {
// shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); //MsgBox.getDefaultShell();
// }
// catch(Exception e) {
//
// }
// }
// ElementListSelectionDialog dlg = new ElementListSelectionDialog(shell, labelProvider);
//
// dlg.setBlockOnOpen(true);
// dlg.setElements(teamList.toArray());
// dlg.setMultipleSelection(false);
// dlg
// .setMessage(NLS.bind(LibraryEditResources.selectTeamsDialog_text, (new Object[] { role.getName() })));
// dlg.setTitle(LibraryEditResources.selectTeamsDialog_title); //$NON-NLS-1$
// dlg.setFilter(null);
// dlg.open();
// Object obj = dlg.getFirstResult();
// // dispose
// labelProvider.dispose();
// return (TeamProfile) obj;
IUserInteractionHandler uiHandler = ExtensionManager
.getDefaultUserInteractionHandler();
if (uiHandler != null) {
ILabelProvider labelProvider = new AdapterFactoryLabelProvider(
TngAdapterFactory.INSTANCE.getOBS_ComposedAdapterFactory());
String title = LibraryEditResources.selectTeamsDialog_title;
String msg = NLS.bind(LibraryEditResources.selectTeamsDialog_text, (new Object[] { role.getName() }));
try {
List selected = uiHandler.select(teamList, labelProvider, false,
teamList, title, msg);
if (selected == null) {
throw new OperationCanceledException();
}
if(selected.isEmpty()) {
return null;
}
return (TeamProfile) selected.get(0);
}
finally {
labelProvider.dispose();
}
}
// no user interaction handler available
// return null
return null;
}
}