blob: 91a6d7440d14329b7793cd0f8d942147baf588ad [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.publishing.ui.wizards;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.epf.authoring.ui.AuthoringUIPlugin;
import org.eclipse.epf.common.utils.FileUtil;
import org.eclipse.epf.library.LibraryService;
import org.eclipse.epf.library.LibraryServiceUtil;
import org.eclipse.epf.library.edit.ui.UserInteractionHelper;
import org.eclipse.epf.library.ui.preferences.LibraryUIPreferences;
import org.eclipse.epf.publishing.services.PublishManager;
import org.eclipse.epf.publishing.services.PublishOptions;
import org.eclipse.epf.publishing.ui.PublishingUIPlugin;
import org.eclipse.epf.publishing.ui.PublishingUIResources;
import org.eclipse.epf.publishing.ui.internal.wizards.PublishConfigWizardExtensionManager;
import org.eclipse.epf.publishing.ui.preferences.PublishingUIPreferences;
import org.eclipse.epf.publishing.wizards.PublishProgressMonitorDialog;
import org.eclipse.epf.publishing.wizards.PublishingOperation;
import org.eclipse.epf.ui.wizards.NewWizardPageContribution;
import org.eclipse.epf.uma.MethodConfiguration;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWizard;
/**
* The Publish Method Configuration wizard.
*
* @author Kelvin Low
* @author Bingxue Xu
* @author Jinhua Xi
* @since 1.0
*/
public class PublishConfigWizard extends Wizard implements INewWizard {
/**
* The wizard ID.
*/
public static final String WIZARD_ID = PublishConfigWizard.class.getName();
// The select configuration wizard page.
protected SelectConfigPage selectConfigPage;
// The select publishing options wizard page.
protected SelectPublishingOptionsPage selectPublishingOptionsPage;
// An extender of this wizard.
protected IPublishConfigWizardExtender wizardExtender;
/**
* Creates a new instance.
*/
public PublishConfigWizard() {
super();
setWindowTitle(PublishingUIResources.publishConfigWizard_title);
}
/**
* @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
*/
public void init(IWorkbench workbench, IStructuredSelection selection) {
wizardExtender = PublishConfigWizardExtensionManager.getInstance()
.getWizardExtender();
if (wizardExtender != null) {
wizardExtender.init(this);
}
}
/**
* @see org.eclipse.jface.wizard.addPages()
*/
public void addPages() {
List wizardPages = new ArrayList();
if (wizardExtender == null) {
selectConfigPage = new SelectConfigPage();
selectPublishingOptionsPage = new SelectPublishingOptionsPage();
wizardPages.add(selectConfigPage);
wizardPages.add(selectPublishingOptionsPage);
} else {
IWizardPage page = wizardExtender
.getReplaceWizardPage(SelectConfigPage.PAGE_NAME);
if (page != null) {
wizardPages.add(page);
} else {
selectConfigPage = new SelectConfigPage();
wizardPages.add(selectConfigPage);
}
page = wizardExtender
.getReplaceWizardPage(SelectPublishingOptionsPage.PAGE_NAME);
if (page != null) {
wizardPages.add(page);
} else {
selectPublishingOptionsPage = new SelectPublishingOptionsPage();
wizardPages.add(selectPublishingOptionsPage);
}
}
if (wizardExtender != null) {
List contributions = wizardExtender.getNewWizardPageContributions();
if (contributions != null) {
for (Iterator it = contributions.iterator(); it.hasNext();) {
NewWizardPageContribution exetnsion = (NewWizardPageContribution) it
.next();
IWizardPage page = (IWizardPage) exetnsion.getWizardPage();
int index = wizardPages.indexOf(page.getName());
if (index == -1) {
wizardPages.add(page);
} else {
if (exetnsion.getInsertAfter()) {
wizardPages.add(index + 1, page);
} else {
wizardPages.add(index, page);
}
}
}
}
}
for (int i = 0; i < wizardPages.size(); i++) {
IWizardPage page = (IWizardPage) wizardPages.get(i);
super.addPage(page);
}
}
/**
* @see org.eclipse.jface.wizard.Wizard#createPageControls(Composite)
*/
public void createPageControls(Composite pageContainer) {
super.createPageControls(pageContainer);
pageContainer.getShell().setImage(
AuthoringUIPlugin.getDefault().getSharedImage(
"full/obj16/MethodConfiguration.gif")); //$NON-NLS-1$
}
/**
* @see org.eclipse.jface.wizard.IWizard#canFinish()
*/
public boolean canFinish() {
if (wizardExtender != null && wizardExtender.canFinish()) {
return true;
}
return super.canFinish();
/*
* return this.getContainer().getCurrentPage() ==
* selectPublishingOptionsPage &&
* selectPublishingOptionsPage.isPageComplete();
*/
}
/**
* @see org.eclipse.jface.wizard.IWizard#performFinish()
*/
/**
* @see org.eclipse.jface.wizard.IWizard#performFinish()
*/
public boolean performFinish() {
String configName = (wizardExtender != null) ? wizardExtender
.getConfigName() : selectConfigPage.getConfigName();
PublishOptions options = (wizardExtender != null) ? wizardExtender
.getPublishingOptions() : selectPublishingOptionsPage
.getPublishingOptions();
options.selectedConfig = configName;
if (checkAndCreateDir(options)) {
PublishingUIPreferences
.setPublishPath(configName, options.getPublicationPath());
PublishingUIPreferences.setTitle(configName, options.getTitle());
PublishingUIPreferences.setBannerImage(configName, options.getBannerImage());
PublishingUIPreferences.setAboutHTML(configName, options.getAboutHTML());
PublishingUIPreferences.setFeedbackURL(configName, options.getFeedbackURL());
PublishingUIPreferences.setIncludeGlossary(configName, options
.isGenerateGlossary());
PublishingUIPreferences.setIncludeIndex(configName, options.isGenerateIndex());
PublishingUIPreferences.setCheckExternalLinks(configName, options
.isCheckExtLinks());
PublishingUIPreferences.setConvertBrokenLinks(configName, options
.isConvertBrokenLinks());
PublishingUIPreferences.setLightWeightTree(configName, options
.isGenerateLightWeightTree());
PublishingUIPreferences.setExtraDescriptorInfo(configName, options
.isShowExtraDescriptorInfo());
PublishingUIPreferences.setPublishUnopenActivitydd(configName, options
.isAutoGenerateActivityDiagrams());
PublishingUIPreferences.setPublishADForActivityExtension(configName, options
.isUnopenExtendedActivityDiagram());
PublishingUIPreferences.saveAllPreferences();
// LibraryUIPreferences.saveAllPreferences();
PublishManager publisher = (wizardExtender != null) ? wizardExtender
.getPublisher()
: new PublishManager();
MethodConfiguration config = LibraryServiceUtil
.getMethodConfiguration(LibraryService.getInstance()
.getCurrentMethodLibrary(), configName);
try {
publisher.init(options.getPublicationPath(), config, options);
PublishingOperation operation = new PublishingOperation(
publisher);
PublishProgressMonitorDialog dlg = new PublishProgressMonitorDialog(
Display.getCurrent().getActiveShell(), publisher
.getViewBuilder());
UserInteractionHelper.runWithProgress(operation, dlg, true,
PublishingUIResources.publishConfigWizard_title);
} finally {
if (publisher != null) {
publisher.dispose();
}
}
return true;
}
return false;
}
/**
* Checks and creates the destination path where the method configuration
* will be published.
*
* @param options
* the publishing options
* @return <code>true</code> if the destination path is valid,
* <code>false</code> otherwise
*/
protected boolean checkAndCreateDir(PublishOptions options) {
String dir = options.publicationPath;
String defaultPublishPath = PublishingUIPreferences
.getDefaultPublishPath();
boolean answer = false;
IPath ecPath = Path.fromOSString(dir);
if (!ecPath.isAbsolute()) {
String path = defaultPublishPath
+ System.getProperty("file.separator") + dir; //$NON-NLS-1$
answer = PublishingUIPlugin
.getDefault()
.getMsgDialog()
.displayPrompt(
PublishingUIResources.publishConfigDialog_title,
PublishingUIResources
.bind(
PublishingUIResources.confirmPathDialog_text,
path));
if (answer) {
options.setPublicationPath(dir);
} else {
return false;
}
}
File file = new File(dir);
if (file.exists()) {
File[] files = file.listFiles();
if (files != null && files.length > 0) {
answer = PublishingUIPlugin
.getDefault()
.getMsgDialog()
.displayConfirmation(
PublishingUIResources.publishConfigDialog_title,
PublishingUIResources
.bind(
PublishingUIResources.overwriteDialog_text,
dir));
if (answer == true) {
try {
answer = FileUtil
.deleteAllFiles(file.getAbsolutePath());
if (answer == false) {
PublishingUIPlugin
.getDefault()
.getMsgDialog()
.displayError(
PublishingUIResources.publishConfigDialog_title,
PublishingUIResources.cannotPublishError_msg,
PublishingUIResources
.bind(
PublishingUIResources.deleteFilesError_reason,
dir));
return false;
}
} catch (Exception e) {
PublishingUIPlugin
.getDefault()
.getMsgDialog()
.displayError(
PublishingUIResources.publishConfigDialog_title,
PublishingUIResources.cannotPublishError_msg,
PublishingUIResources
.bind(
PublishingUIResources.deleteFilesError_reason,
dir), e);
return false;
}
}
} else {
return true;
}
} else {
try {
answer = file.mkdirs();
} catch (Exception e) {
PublishingUIPlugin.getDefault().getMsgDialog().displayError(
PublishingUIResources.publishConfigDialog_title,
PublishingUIResources.cannotPublishError_msg,
PublishingUIResources.bind(
PublishingUIResources.createDirError_reason,
file.getAbsolutePath()), e);
return false;
}
if (!answer) {
PublishingUIPlugin.getDefault().getMsgDialog().displayError(
PublishingUIResources.publishConfigDialog_title,
PublishingUIResources.cannotPublishError_msg,
PublishingUIResources.bind(
PublishingUIResources.createDirError_reason,
file.getAbsolutePath()));
return false;
}
}
return answer;
}
}