| //------------------------------------------------------------------------------ |
| // 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 org.eclipse.core.runtime.IPath; |
| import org.eclipse.core.runtime.Path; |
| import org.eclipse.epf.authoring.ui.AuthoringUIHelpContexts; |
| import org.eclipse.epf.authoring.ui.AuthoringUIPlugin; |
| import org.eclipse.epf.authoring.ui.AuthoringUIText; |
| import org.eclipse.epf.common.utils.StrUtil; |
| import org.eclipse.epf.publishing.services.PublishOptions; |
| import org.eclipse.epf.publishing.ui.PublishingUIResources; |
| import org.eclipse.epf.publishing.ui.preferences.PublishingPreferencePage; |
| import org.eclipse.epf.publishing.ui.preferences.PublishingUIPreferences; |
| import org.eclipse.epf.ui.wizards.BaseWizardPage; |
| import org.eclipse.jface.wizard.IWizardPage; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.events.ModifyEvent; |
| import org.eclipse.swt.events.ModifyListener; |
| import org.eclipse.swt.events.SelectionAdapter; |
| import org.eclipse.swt.events.SelectionEvent; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.layout.GridLayout; |
| import org.eclipse.swt.widgets.Button; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.DirectoryDialog; |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.swt.widgets.Event; |
| import org.eclipse.swt.widgets.FileDialog; |
| import org.eclipse.swt.widgets.Group; |
| import org.eclipse.swt.widgets.Listener; |
| import org.eclipse.swt.widgets.Text; |
| import org.eclipse.ui.PlatformUI; |
| |
| /** |
| * A wizard page that prompts the user to select the publishing options for a |
| * web site. |
| * |
| * @author Kelvin Low |
| * @author Bingxue Xu |
| * @author Jinhua Xi |
| * @since 1.0 |
| */ |
| public class SelectPublishingOptionsPage extends BaseWizardPage { |
| |
| /** |
| * The wizard page name. |
| */ |
| public static final String PAGE_NAME = SelectPublishingOptionsPage.class |
| .getName(); |
| |
| private Text destinationPathText; |
| |
| private Text titleText; |
| |
| private Text bannerImageText; |
| |
| private Text aboutHTMLText; |
| |
| private Text feedbackURLText; |
| |
| private Button browseButton; |
| |
| private Button defaultPathCheckbox; |
| |
| private Button selectImageButton; |
| |
| private Button selectHTMLButton; |
| |
| private Button includeGlossary; |
| |
| private Button includeIndex; |
| |
| private Button checkExternalLinks; |
| |
| private Button convertBrokenLinks; |
| |
| private Button autoGenerateAD; |
| |
| private boolean displayDestinationGroup = true; |
| |
| private Button extraDescriptorInfoCtr; |
| |
| private Button lightWeightTreeCtr; |
| |
| private Button publishUnopenADD; |
| |
| private String configName = ""; |
| |
| /** |
| * Creates a new instance. |
| * |
| * @param name |
| * the name of the wizard page |
| */ |
| public SelectPublishingOptionsPage(String name) { |
| super(name); |
| setTitle(PublishingUIResources.publishConfigWizard_selectOptionsPage_title); |
| setDescription(PublishingUIResources.publishConfigWizard_selectOptionsPage_text); |
| setImageDescriptor(AuthoringUIPlugin.getDefault().getImageDescriptor( |
| "full/wizban/PublishConfiguration.gif")); //$NON-NLS-1$ |
| } |
| |
| /** |
| * Creates a new instance. |
| */ |
| public SelectPublishingOptionsPage() { |
| this(PAGE_NAME); |
| } |
| |
| /** |
| * @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)); |
| |
| createDestinationDirGroup(composite); |
| createPublishedWebSiteGroup(composite); |
| createPublishingOptionsGroups(composite); |
| |
| initControls(); |
| |
| addListeners(composite); |
| |
| setControl(composite); |
| |
| PlatformUI |
| .getWorkbench() |
| .getHelpSystem() |
| .setHelp( |
| composite, |
| AuthoringUIHelpContexts.CONFIGURATION_PUBLISH_WIZARD_ALL_PAGES_CONTEXT); |
| } |
| |
| /** |
| * Creatres the destination directory group to this wizard page. |
| * |
| * @param composite |
| * the parent composite |
| */ |
| protected void createDestinationDirGroup(Composite composite) { |
| if (displayDestinationGroup) { |
| Group destinationGroup = new Group(composite, SWT.NULL); |
| destinationGroup.setLayout(new GridLayout(3, false)); |
| destinationGroup.setLayoutData(new GridData( |
| GridData.FILL_HORIZONTAL)); |
| destinationGroup |
| .setText(PublishingUIResources.publishConfigWizard_destinationGroup_text); |
| |
| createLabel(destinationGroup, |
| PublishingUIResources.publishConfigWizard_directory_text); |
| destinationPathText = createEditableText(destinationGroup, |
| "", 360, 1); //$NON-NLS-1$ |
| browseButton = new Button(destinationGroup, SWT.NONE); |
| browseButton.setText(AuthoringUIText.BROWSE_BUTTON_TEXT); |
| browseButton.setEnabled(false); |
| |
| createLabel(destinationGroup, ""); //$NON-NLS-1$ |
| defaultPathCheckbox = createCheckbox( |
| destinationGroup, |
| PublishingUIResources.publishConfigWizard_useDefaultPath_text, |
| 2); |
| defaultPathCheckbox.setSelection(destinationPathText.getText() |
| .equals(PublishingUIPreferences.getDefaultPublishPath())); |
| destinationPathText.setEnabled(!defaultPathCheckbox.getSelection()); |
| |
| if (!defaultPathCheckbox.getSelection()) { |
| browseButton.setEnabled(true); |
| } |
| } |
| } |
| |
| /** |
| * Creates the published web site group to this wizard page. |
| * |
| * @param composite |
| * the parent composite |
| */ |
| protected void createPublishedWebSiteGroup(Composite composite) { |
| Group webSiteGroup = new Group(composite, SWT.NULL); |
| webSiteGroup.setLayout(new GridLayout(3, false)); |
| webSiteGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| webSiteGroup |
| .setText(PublishingUIResources.publishConfigWizard_webSite_text); |
| |
| createLabel(webSiteGroup, |
| PublishingUIResources.publishConfigWizard_title_text); |
| titleText = createEditableText(webSiteGroup, "", 360, 1); //$NON-NLS-1$ |
| createLabel(webSiteGroup, ""); //$NON-NLS-1$ |
| |
| createLabel(webSiteGroup, |
| PublishingUIResources.publishConfigWizard_bannerImage_text); |
| bannerImageText = createEditableText(webSiteGroup, "", 360, 1); //$NON-NLS-1$ |
| selectImageButton = new Button(webSiteGroup, SWT.NONE); |
| selectImageButton.setText(AuthoringUIText.SELECT_BUTTON_TEXT); |
| |
| createLabel(webSiteGroup, |
| PublishingUIResources.publishConfigWizard_aboutHTML_text); |
| aboutHTMLText = createEditableText(webSiteGroup, "", 360, 1); //$NON-NLS-1$ |
| selectHTMLButton = new Button(webSiteGroup, SWT.NONE); |
| selectHTMLButton.setText(AuthoringUIText.SELECT_BUTTON_TEXT); |
| |
| createLabel(webSiteGroup, |
| PublishingUIResources.publishConfigWizard_feedbackURL_text); |
| feedbackURLText = createEditableText(webSiteGroup, "", 360, 1); //$NON-NLS-1$ |
| createLabel(webSiteGroup, ""); //$NON-NLS-1$ |
| |
| includeGlossary = createCheckbox(webSiteGroup, |
| PublishingUIResources.publishConfigWizard_includeGlossary_text, |
| 3); |
| includeIndex = createCheckbox(webSiteGroup, |
| PublishingUIResources.publishConfigWizard_includeIndex_text, 3); |
| |
| // Provide a means to add additional options to this group. |
| includeAdditionalPublishingOptions(webSiteGroup); |
| } |
| |
| /** |
| * Provide a means to add additional options to the published web site |
| * group. |
| * |
| * @param composite |
| * the parent composite |
| */ |
| protected void includeAdditionalPublishingOptions(Composite composite) { |
| } |
| |
| /** |
| * Creates the publishing options groups to this wizard page. |
| * |
| * @param composite |
| * the parent composite |
| */ |
| protected void createPublishingOptionsGroups(Composite composite) { |
| // Create the validation group. |
| Group validationGroup = new Group(composite, SWT.NULL); |
| validationGroup.setLayout(new GridLayout(1, false)); |
| validationGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| validationGroup |
| .setText(PublishingUIResources.publishConfigWizard_validationGroup_text); |
| |
| checkExternalLinks = createCheckbox(validationGroup, |
| PublishingUIResources.publishConfigWizard_checkHyperlinks_text); |
| |
| convertBrokenLinks = createCheckbox( |
| validationGroup, |
| PublishingUIResources.publishConfigWizard_convertBrokenLinks_text); |
| |
| // Create the diagrams group. |
| Group diagramGroup = new Group(composite, SWT.NULL); |
| diagramGroup.setLayout(new GridLayout(1, false)); |
| diagramGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| diagramGroup |
| .setText(PublishingUIResources.publishConfigWizard_diagramGroup_text); |
| |
| autoGenerateAD = createCheckbox( |
| diagramGroup, |
| PublishingUIResources.publishConfigWizard_publish_unopen_activity_dd_text); |
| |
| publishUnopenADD = createCheckbox( |
| diagramGroup, |
| PublishingUIResources.publishConfigWizard_publish_extend_activity_diagram); |
| |
| // Create the layout group. |
| Group layoutGroup = new Group(composite, SWT.NULL); |
| layoutGroup.setLayout(new GridLayout()); |
| layoutGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| layoutGroup |
| .setText(PublishingUIResources.publishConfigWizard_layout_text); |
| |
| lightWeightTreeCtr = createCheckbox(layoutGroup, |
| PublishingUIResources.publishConfigWizard_lightWeightTree_text); |
| |
| extraDescriptorInfoCtr = createCheckbox( |
| layoutGroup, |
| PublishingUIResources.publishConfigWizard_extraDescriptorInfo_text); |
| extraDescriptorInfoCtr |
| .setSelection(PublishingUIPreferences |
| .getBooleanValue(PublishingPreferencePage.EXTRA_DESCRIPTOR_INFO)); |
| } |
| |
| /** |
| * Initializes the wizard page controls with data. |
| */ |
| protected void initControls() { |
| } |
| |
| /** |
| * @see org.eclipse.epf.ui.wizards.BaseWizardPage#onEnterPage(Object) |
| */ |
| public void onEnterPage(Object obj) { |
| super.onEnterPage(obj); |
| if (obj instanceof String) { |
| configName = (String) obj; |
| } else { |
| configName = ""; //$NON-NLS-1$ |
| } |
| String initPath = PublishingUIPreferences.getPublishPath(configName); |
| if (initPath == null || initPath.length() == 0) { |
| initPath = PublishingUIPreferences.getDefaultPublishPath(); |
| } |
| destinationPathText.setText(initPath); |
| defaultPathCheckbox.setSelection(destinationPathText.getText().equals( |
| PublishingUIPreferences.getDefaultPublishPath())); |
| destinationPathText.setEnabled(!defaultPathCheckbox.getSelection()); |
| |
| if (!defaultPathCheckbox.getSelection()) { |
| browseButton.setEnabled(true); |
| } |
| titleText.setText(PublishingUIPreferences.getTitle(configName)); |
| bannerImageText.setText(PublishingUIPreferences |
| .getBannerImage(configName)); |
| aboutHTMLText.setText(PublishingUIPreferences.getAboutHTML(configName)); |
| String feedbackURL = PublishingUIPreferences.getFeedbackURL(configName); |
| if (feedbackURL == null || feedbackURL.length() <= 0) |
| feedbackURL = PublishingUIPreferences.getDefaultFeedbackURL(); |
| feedbackURLText.setText(feedbackURL); |
| includeGlossary.setSelection(PublishingUIPreferences |
| .getIncludeGlossary(configName)); |
| includeIndex.setSelection(PublishingUIPreferences |
| .getIncludeIndex(configName)); |
| checkExternalLinks.setSelection(PublishingUIPreferences |
| .getCheckExternalLinks(configName)); |
| convertBrokenLinks.setSelection(PublishingUIPreferences |
| .getConvertBrokenLinks(configName)); |
| autoGenerateAD.setSelection(PublishingUIPreferences |
| .getPublishADForActivityExtension(configName)); |
| publishUnopenADD.setSelection(PublishingUIPreferences |
| .getPublishUnopenActivitydd(configName)); |
| lightWeightTreeCtr.setSelection(PublishingUIPreferences |
| .getLightWeightTree(configName)); |
| extraDescriptorInfoCtr.setSelection(PublishingUIPreferences |
| .getExtraDescriptorInfo(configName)); |
| } |
| |
| /** |
| * @see org.eclipse.jface.wizard.WizardPage#isPageComplete() |
| */ |
| public boolean isPageComplete() { |
| if (!displayDestinationGroup) { |
| return true; |
| } |
| |
| if (!isTextNonEmpty(destinationPathText)) { |
| setErrorMessage(PublishingUIResources.invalidPathError_msg); |
| return false; |
| } |
| |
| String path = destinationPathText.getText(); |
| IPath ecPath = Path.fromOSString(path); |
| boolean isValid = ecPath.isValidPath(path); |
| if (!isValid) { |
| setErrorMessage(PublishingUIResources.invalidPathError_msg); |
| } else if (!StrUtil.isValidPublishPath(path)) { |
| setErrorMessage(PublishingUIResources.invalidPathCharsError_msg); |
| } else { |
| setErrorMessage(null); |
| return true; |
| } |
| |
| return false; |
| } |
| |
| /** |
| * @see org.eclipse.jface.wizard.WizardPage#getNextPage() |
| */ |
| public IWizardPage getNextPage() { |
| return null; |
| } |
| |
| /** |
| * Adds the listeners for the controls on this page. |
| */ |
| private void addListeners(final Composite composite) { |
| if (displayDestinationGroup) { |
| destinationPathText.addModifyListener(new ModifyListener() { |
| public void modifyText(ModifyEvent e) { |
| setPageComplete(isPageComplete()); |
| } |
| }); |
| |
| browseButton.addSelectionListener(new SelectionAdapter() { |
| public void widgetSelected(SelectionEvent event) { |
| try { |
| DirectoryDialog dd = new DirectoryDialog(composite |
| .getShell(), SWT.NONE); |
| String destination = dd.open(); |
| if (destination != null) { |
| destinationPathText.setText(destination); |
| } |
| } catch (Exception e) { |
| e.printStackTrace(); |
| } |
| } |
| }); |
| |
| defaultPathCheckbox.addListener(SWT.Selection, new Listener() { |
| public void handleEvent(Event event) { |
| if (defaultPathCheckbox.getSelection()) { |
| destinationPathText.setText(PublishingUIPreferences |
| .getDefaultPublishPath()); |
| destinationPathText.setEnabled(false); |
| browseButton.setEnabled(false); |
| } else { |
| String initPath = PublishingUIPreferences |
| .getPublishPath(configName); |
| if (initPath == null || initPath.length() <= 0) |
| initPath = PublishingUIPreferences |
| .getDefaultPublishPath(); |
| destinationPathText.setText(initPath); |
| destinationPathText.setEnabled(true); |
| browseButton.setEnabled(true); |
| } |
| } |
| }); |
| } |
| |
| selectImageButton.addSelectionListener(new SelectionAdapter() { |
| public void widgetSelected(SelectionEvent event) { |
| try { |
| FileDialog dialog = new FileDialog(composite.getShell(), |
| SWT.OPEN); |
| dialog.setFilterExtensions(new String[] { |
| "*.gif", "*.jpg", "*.bmp" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| String imageFile = dialog.open(); |
| if (imageFile != null) { |
| bannerImageText.setText(imageFile); |
| } |
| } catch (Exception e) { |
| e.printStackTrace(); |
| } |
| } |
| }); |
| |
| selectHTMLButton.addSelectionListener(new SelectionAdapter() { |
| public void widgetSelected(SelectionEvent event) { |
| try { |
| FileDialog dialog = new FileDialog(composite.getShell(), |
| SWT.OPEN); |
| dialog |
| .setFilterExtensions(new String[] { |
| "*.htm", "*.html" }); //$NON-NLS-1$ //$NON-NLS-2$ |
| String htmlFile = dialog.open(); |
| if (htmlFile != null) { |
| aboutHTMLText.setText(htmlFile); |
| } |
| } catch (Exception e) { |
| e.printStackTrace(); |
| } |
| } |
| }); |
| } |
| |
| /** |
| * @see org.eclipse.jface.dialogs.DialogPage#setVisible() |
| */ |
| public void setVisible(boolean visible) { |
| super.setVisible(visible); |
| if (visible) { |
| Display display = titleText.getDisplay(); |
| if (!(display == null || display.isDisposed())) { |
| display.asyncExec(new Runnable() { |
| public void run() { |
| titleText.setFocus(); |
| } |
| }); |
| } |
| } |
| } |
| |
| /** |
| * Gets the user selected publishing options. |
| * |
| * @return a <code>PublishOptions</code> object |
| */ |
| public PublishOptions getPublishingOptions() { |
| PublishOptions options = new PublishOptions(); |
| |
| options.publishConfiguration = true; |
| if (displayDestinationGroup) { |
| options.setPublicationPath(getDestinationPath()); |
| } |
| options.setTitle(getWebSiteTitle()); |
| options.setBannerImage(getBannerImagePath()); |
| options.setAboutHTML(getAboutHTMLPath()); |
| options.setFeedbackURL(getFeedbackURL()); |
| options.setGenerateGlossary(getIncludeGlossarySelection()); |
| options.setGenerateIndex(getIncludeIndexSelection()); |
| options.setCheckExtLinks(getCheckExternalLinksSelection()); |
| options.setAutoGenerateActivityDiagrams(getAutoGenerateADSelection()); |
| options |
| .setUnopenExtendedActivityDiagram(getPublishUnopenADDSelection()); |
| options.setConvertBrokenLinks(getConvertBrokenLinksSelection()); |
| options |
| .setShowExtraDescriptorInfo(getShowExtraDescriptorInfoSelection()); |
| options |
| .setGenerateLightWeightTree(getGenerateLightWeightTreeSelection()); |
| |
| return options; |
| } |
| |
| /** |
| * Gets the user specified destination path. |
| */ |
| protected String getDestinationPath() { |
| return destinationPathText.getText().trim(); |
| } |
| |
| /** |
| * Gets the user specified web site title. |
| */ |
| protected String getWebSiteTitle() { |
| return titleText.getText().trim(); |
| } |
| |
| /** |
| * Gets the user specified banner image path. |
| */ |
| protected String getBannerImagePath() { |
| return bannerImageText.getText().trim(); |
| } |
| |
| /** |
| * Gets the user specified about HTML path. |
| */ |
| protected String getAboutHTMLPath() { |
| return aboutHTMLText.getText().trim(); |
| } |
| |
| /** |
| * Gets the user specified feedback URL. |
| */ |
| protected String getFeedbackURL() { |
| return feedbackURLText.getText().trim(); |
| } |
| |
| /** |
| * Gets the user specified include glossary selection. |
| */ |
| protected boolean getIncludeGlossarySelection() { |
| return includeGlossary.getSelection(); |
| } |
| |
| /** |
| * Gets the user specified include index selection. |
| */ |
| protected boolean getIncludeIndexSelection() { |
| return includeIndex.getSelection(); |
| } |
| |
| /** |
| * Gets the user specified check external links selection. |
| */ |
| protected boolean getCheckExternalLinksSelection() { |
| return checkExternalLinks.getSelection(); |
| } |
| |
| /** |
| * Gets the user specified convert broken links selection. |
| */ |
| protected boolean getConvertBrokenLinksSelection() { |
| return convertBrokenLinks.getSelection(); |
| } |
| |
| /** |
| * Gets the user specified auto generate activity diagrams selection. |
| */ |
| protected boolean getAutoGenerateADSelection() { |
| return autoGenerateAD.getSelection(); |
| } |
| |
| /** |
| * Gets the user specified publish unopen extend activity diagram selection. |
| */ |
| protected boolean getPublishUnopenADDSelection() { |
| return publishUnopenADD.getSelection(); |
| } |
| |
| /** |
| * Gets the user specified show extra descriptor info selection. |
| */ |
| protected boolean getShowExtraDescriptorInfoSelection() { |
| return extraDescriptorInfoCtr.getSelection(); |
| } |
| |
| /** |
| * Gets the user specified generate light weight tree selection. |
| */ |
| protected boolean getGenerateLightWeightTreeSelection() { |
| return lightWeightTreeCtr.getSelection(); |
| } |
| |
| /** |
| * @see org.eclipse.jface.wizard.WizardPage#dispose() |
| */ |
| public void dispose() { |
| PublishingUIPreferences |
| .setPublishPath(configName, getDestinationPath()); |
| PublishingUIPreferences.setTitle(configName, getWebSiteTitle()); |
| PublishingUIPreferences |
| .setBannerImage(configName, getBannerImagePath()); |
| PublishingUIPreferences.setAboutHTML(configName, getAboutHTMLPath()); |
| PublishingUIPreferences.setFeedbackURL(configName, getFeedbackURL()); |
| PublishingUIPreferences.setIncludeGlossary(configName, |
| getIncludeGlossarySelection()); |
| PublishingUIPreferences.setIncludeIndex(configName, |
| getIncludeIndexSelection()); |
| PublishingUIPreferences.setCheckExternalLinks(configName, |
| getCheckExternalLinksSelection()); |
| PublishingUIPreferences.setConvertBrokenLinks(configName, |
| getConvertBrokenLinksSelection()); |
| PublishingUIPreferences.setPublishADForActivityExtension(configName, |
| getAutoGenerateADSelection()); |
| PublishingUIPreferences.setPublishUnopenActivitydd(configName, |
| getPublishUnopenADDSelection()); |
| PublishingUIPreferences.setExtraDescriptorInfo(configName, |
| getShowExtraDescriptorInfoSelection()); |
| PublishingUIPreferences.setLightWeightTree(configName, |
| getGenerateLightWeightTreeSelection()); |
| super.dispose(); |
| } |
| } |