| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2007 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.publishing.ui.wizards; |
| |
| import java.util.ArrayList; |
| import java.util.Iterator; |
| import java.util.List; |
| |
| import org.eclipse.epf.authoring.ui.AuthoringUIHelpContexts; |
| import org.eclipse.epf.authoring.ui.AuthoringUIText; |
| import org.eclipse.epf.common.utils.StrUtil; |
| import org.eclipse.epf.library.LibraryService; |
| import org.eclipse.epf.library.LibraryServiceUtil; |
| import org.eclipse.epf.library.configuration.ConfigurationHelper; |
| import org.eclipse.epf.publishing.ui.PublishingUIPlugin; |
| import org.eclipse.epf.publishing.ui.PublishingUIResources; |
| import org.eclipse.epf.ui.wizards.BaseWizardPage; |
| import org.eclipse.epf.uma.ContentCategory; |
| import org.eclipse.epf.uma.MethodConfiguration; |
| import org.eclipse.jface.viewers.ArrayContentProvider; |
| import org.eclipse.jface.viewers.ISelectionChangedListener; |
| import org.eclipse.jface.viewers.ITableLabelProvider; |
| import org.eclipse.jface.viewers.LabelProvider; |
| import org.eclipse.jface.viewers.SelectionChangedEvent; |
| import org.eclipse.jface.viewers.StructuredSelection; |
| import org.eclipse.jface.viewers.TableViewer; |
| import org.eclipse.jface.wizard.IWizardPage; |
| import org.eclipse.jface.wizard.WizardPage; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.graphics.Image; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.layout.GridLayout; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Table; |
| import org.eclipse.swt.widgets.TableItem; |
| import org.eclipse.swt.widgets.Text; |
| import org.eclipse.ui.PlatformUI; |
| |
| /** |
| * A wizard page that prompts the user to select a method configuration to |
| * publish. |
| * |
| * @author Kelvin Low |
| * @author Bingxue Xu |
| * @author Jinhua Xi |
| * @since 1.0 |
| */ |
| public class SelectConfigPage extends BaseWizardPage { |
| |
| /** |
| * The wizard page name. |
| */ |
| public static final String PAGE_NAME = SelectConfigPage.class.getName(); |
| |
| private Table table; |
| |
| private TableViewer configViewer; |
| |
| private Text briefDescText; |
| |
| private List processViews; |
| |
| private String selectedConfigName; |
| |
| private class ConfigurationTableLabelProvider extends LabelProvider |
| implements ITableLabelProvider { |
| |
| public Image getColumnImage(Object element, int index) { |
| return null; |
| } |
| |
| public String getColumnText(Object element, int index) { |
| MethodConfiguration config = (MethodConfiguration) element; |
| return config.getName(); |
| } |
| } |
| |
| /** |
| * Creates a new instance. |
| */ |
| public SelectConfigPage() { |
| super(PAGE_NAME); |
| setTitle(PublishingUIResources.selectConfigWizardPage_title); |
| setDescription(PublishingUIResources.selectConfigWizardPage_text); |
| setImageDescriptor(PublishingUIPlugin.getDefault().getImageDescriptor( |
| "full/wizban/PublishConfiguration.gif")); //$NON-NLS-1$ |
| } |
| |
| /** |
| * @see org.eclipse.jface.dialogs.IDialogPage#createControl(Composite) |
| */ |
| public void createControl(Composite parent) { |
| Composite composite = new Composite(parent, SWT.NULL); |
| composite.setLayout(new GridLayout(1, false)); |
| |
| createLabel(composite, PublishingUIResources.configLabel_text); |
| |
| table = new Table(composite, SWT.BORDER | SWT.V_SCROLL); |
| GridData gridData = new GridData(GridData.FILL_BOTH); |
| gridData.heightHint = 120; |
| gridData.widthHint = 280; |
| table.setLayoutData(gridData); |
| |
| configViewer = new TableViewer(table); |
| |
| createLabel(composite, AuthoringUIText.DESCRIPTION_TEXT); |
| |
| briefDescText = createTextMulti(composite, "", 360, 80, 1); //$NON-NLS-1$ |
| |
| initControls(); |
| |
| setControl(composite); |
| |
| PlatformUI |
| .getWorkbench() |
| .getHelpSystem() |
| .setHelp( |
| composite, |
| AuthoringUIHelpContexts.CONFIGURATION_PUBLISH_WIZARD_ALL_PAGES_CONTEXT); |
| } |
| |
| /** |
| * Initializes the wizard page controls with data. |
| */ |
| protected void initControls() { |
| configViewer.setLabelProvider(new ConfigurationTableLabelProvider()); |
| configViewer.setContentProvider(new ArrayContentProvider()); |
| MethodConfiguration[] configs = LibraryServiceUtil |
| .getMethodConfigurations(LibraryService.getInstance() |
| .getCurrentMethodLibrary()); |
| configViewer.setInput(configs); |
| |
| // Select the first config and display its brief description. |
| if (configs.length > 0) { |
| table.select(0); |
| setBriefDescription(configs[0]); |
| } |
| |
| addListeners(); |
| } |
| |
| /** |
| * Adds event handlers to the wizard page controls. |
| */ |
| protected void addListeners() { |
| configViewer |
| .addSelectionChangedListener(new ISelectionChangedListener() { |
| public void selectionChanged(SelectionChangedEvent event) { |
| StructuredSelection selection = (StructuredSelection) event |
| .getSelection(); |
| if (!selection.isEmpty()) { |
| Object[] configs = selection.toArray(); |
| setBriefDescription((MethodConfiguration) configs[0]); |
| } |
| setPageComplete(isPageComplete()); |
| getWizard().getContainer().updateButtons(); |
| } |
| }); |
| } |
| |
| /** |
| * @see org.eclipse.jface.wizard.WizardPage#isCompleted() |
| */ |
| public boolean isPageComplete() { |
| if (getErrorMessage() != null) |
| return false; |
| |
| int count = table.getSelectionCount(); |
| |
| if (count > 0) { |
| TableItem[] items = table.getSelection(); |
| selectedConfigName = items[0].getText(); |
| MethodConfiguration config = LibraryServiceUtil |
| .getMethodConfiguration(LibraryService.getInstance() |
| .getCurrentMethodLibrary(), selectedConfigName); |
| processViews = null; |
| if (config != null) { |
| // FIXME! Review implementation. |
| // processViews = config.getProcessViews(); |
| processViews = getValidConfigViews(config); |
| } |
| |
| if (processViews != null && processViews.size() > 0) { |
| setErrorMessage(null); |
| setMessage(null); |
| return true; |
| } else { |
| setErrorMessage(null); |
| setMessage(PublishingUIResources.missingViewError_msg, |
| WizardPage.WARNING); |
| } |
| } |
| |
| return false; |
| } |
| |
| /** |
| * @see org.eclipse.jface.wizard.WizardPage#getNextPage() |
| */ |
| public IWizardPage getNextPage() { |
| IWizardPage page = getWizard().getNextPage(this); |
| try { |
| ((BaseWizardPage) page).onEnterPage(getConfigName()); |
| } catch (Exception e) { |
| } |
| return page; |
| } |
| |
| /** |
| * Gets a list of valid configuration views. |
| * |
| * @param config |
| * a method configuration |
| * @return a list of configuration views |
| */ |
| protected List getValidConfigViews(MethodConfiguration config) { |
| String msg; |
| StringBuffer message = new StringBuffer(); |
| List views = new ArrayList(); |
| for (Iterator it = config.getProcessViews().iterator(); it.hasNext();) { |
| ContentCategory view = (ContentCategory) it.next(); |
| if (ConfigurationHelper.isContributor(view)) { |
| msg = PublishingUIResources.bind( |
| PublishingUIResources.invalidViewContributorInfo_msg, |
| view.getPresentationName()); |
| message.append(StrUtil.TAB).append(msg).append( |
| StrUtil.LINE_FEED); |
| } else { |
| view = (ContentCategory) ConfigurationHelper |
| .getCalculatedElement(view, config); |
| if (view == null) { |
| msg = PublishingUIResources.bind( |
| PublishingUIResources.invalidViewInvalidInfo_msg, |
| view.getPresentationName()); |
| message.append(StrUtil.TAB).append(msg).append( |
| StrUtil.LINE_FEED); |
| |
| } else if (views.contains(view)) { |
| msg = PublishingUIResources.bind( |
| PublishingUIResources.invalidViewSameViewInfo_msg, |
| view.getPresentationName()); |
| message.append(StrUtil.TAB).append(msg).append( |
| StrUtil.LINE_FEED); |
| |
| } else { |
| views.add(view); |
| } |
| } |
| } |
| |
| if (message.length() > 0) { |
| msg = PublishingUIResources.bind( |
| PublishingUIResources.invalidViewsInfo_msg, config |
| .getName()); |
| message.insert(0, msg + StrUtil.LINE_FEED + StrUtil.LINE_FEED); |
| |
| // FIXME! Should not display warning messages in the brief |
| // description field. |
| briefDescText.setText(message.toString()); |
| } |
| |
| return views; |
| } |
| |
| /** |
| * Gets the user selected method configuration. |
| * |
| * @return the name of the user selected configuration or <code>null</code> |
| */ |
| public String getConfigName() { |
| return selectedConfigName; |
| } |
| |
| /** |
| * Populates the Brief Description text control with the given |
| * configuration's brief descripotion. |
| */ |
| private void setBriefDescription(MethodConfiguration config) { |
| briefDescText.setText(config.getBriefDescription()); |
| } |
| |
| } |