import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.DialogSettings;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Widget;
-import org.eclipse.ui.dialogs.ContainerSelectionDialog;
import org.eclipse.ui.dialogs.WizardExportResourcesPage;
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
public final class WikiPDFExportWizardPage extends WizardExportResourcesPage implements IPropertyChangeListener, SelectionListener {
- private StringFieldEditor folderText;
+// private StringFieldEditor folderText;
- private static final String[] PDF_EXTENSION = { "pdf" };
+ private static final String[] PDF_EXTENSION = { "*.pdf" };
//dialog store id constants
- private static final String STORE_DESTINATION_NAMES_ID = "WikiPDFExportWizardPage.STORE_DESTINATION_NAMES_ID"; //$NON-NLS-1$
+ private static final String PAGE_NAME = "WikiPDFExportWizardPage"; //$NON-NLS-1$
+
+ private static final String STORE_DESTINATION_NAMES = PAGE_NAME+".STORE_DESTINATION_NAMES"; //$NON-NLS-1$
- private static final String STORE_OVERWRITE_EXISTING_FILES_ID = "WikiPDFExportWizardPage.STORE_OVERWRITE_EXISTING_FILES_ID"; //$NON-NLS-1$
+ private static final String STORE_OVERWRITE_EXISTING_FILES_ID = PAGE_NAME+".STORE_OVERWRITE_EXISTING_FILES_ID"; //$NON-NLS-1$
- private StringFieldEditor exportFileText;
+// private StringFieldEditor exportFileText;
- private Combo destinationNameField;
+ private Combo fDestinationNamesCombo;
private Button destinationBrowseButton;
protected Button overwriteExistingFilesCheckbox;
- private ISelection selection;
+ private ISelection fInitialSelection;
+ private IDialogSettings fSettings = null;
public WikiPDFExportWizardPage(IStructuredSelection selection) {
- super(WikiEditorPlugin.getResourceString("Export.wizardTitle"), selection);
+ super(PAGE_NAME, selection);
setTitle(WikiEditorPlugin.getResourceString("Export.wizardTitle"));
setDescription(WikiEditorPlugin.getResourceString("Export.wizardDescription"));
- this.selection = selection;
+ this.fInitialSelection = selection;
}
/**
destinationLabel.setFont(font);
// destination name entry field
- destinationNameField = new Combo(destinationSelectionGroup, SWT.SINGLE | SWT.BORDER);
- destinationNameField.addListener(SWT.Modify, this);
- destinationNameField.addListener(SWT.Selection, this);
+ fDestinationNamesCombo = new Combo(destinationSelectionGroup, SWT.SINGLE | SWT.BORDER);
+ fDestinationNamesCombo.addListener(SWT.Modify, this);
+ fDestinationNamesCombo.addListener(SWT.Selection, this);
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
- destinationNameField.setLayoutData(data);
- destinationNameField.setFont(font);
+ fDestinationNamesCombo.setLayoutData(data);
+ fDestinationNamesCombo.setFont(font);
// destination browse button
destinationBrowseButton = new Button(destinationSelectionGroup, SWT.PUSH);
new Label(parent, SWT.NONE); // vertical spacer
}
+
/**
- * Create the options specification widgets.
- *
- * @param parent org.eclipse.swt.widgets.Composite
- */
- protected void createOptionsGroup(Composite parent) {
- // options group
- Group optionsGroup = new Group(parent, SWT.NONE);
- GridLayout layout = new GridLayout();
- optionsGroup.setLayout(layout);
- optionsGroup.setLayoutData(
- new GridData(
- GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
- optionsGroup.setText(IDEWorkbenchMessages.getString("WizardExportPage.options")); //$NON-NLS-1$
- optionsGroup.setFont(parent.getFont());
-
- createOptionsGroupButtons(optionsGroup);
+ * Create the options specification widgets.
+ *
+ * @param parent
+ * org.eclipse.swt.widgets.Composite
+ */
+ protected void createOptionsGroup(Composite parent) {
+ // options group
+ Group optionsGroup = new Group(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ optionsGroup.setLayout(layout);
+ optionsGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
+ optionsGroup.setText(IDEWorkbenchMessages.getString("WizardExportPage.options")); //$NON-NLS-1$
+ optionsGroup.setFont(parent.getFont());
+
+ createOptionsGroupButtons(optionsGroup);
+
+ }
- }
/**
- * Create the buttons in the options group.
- */
+ * Create the buttons in the options group.
+ */
- protected void createOptionsGroupButtons(Group optionsGroup) {
+ protected void createOptionsGroupButtons(Group optionsGroup) {
- Font font = optionsGroup.getFont();
- createOverwriteExisting(optionsGroup, font);
+ Font font = optionsGroup.getFont();
+ createOverwriteExisting(optionsGroup, font);
+
+ // createDirectoryStructureOptions(optionsGroup, font);
+ }
-// createDirectoryStructureOptions(optionsGroup, font);
- }
/**
* Create the button for checking if we should ask if we are going to overwrite existing files.
*
* Open an appropriate destination browser so that the user can specify a source to import from
*/
protected void handleDestinationBrowseButtonPressed() {
- DirectoryDialog dialog = new DirectoryDialog(getContainer().getShell(), SWT.SAVE);
- dialog.setMessage("Select destination");
- dialog.setText("Select title");
+ FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.SAVE);
+ dialog.setFilterExtensions(PDF_EXTENSION);
+ dialog.setText("Select pdf file");
dialog.setFilterPath(getDestinationValue());
- String selectedDirectoryName = dialog.open();
+ String selectedFileName = dialog.open();
- if (selectedDirectoryName != null) {
+ if (selectedFileName != null) {
setErrorMessage(null);
- setDestinationValue(selectedDirectoryName);
+ setDestinationValue(selectedFileName);
}
}
+// /**
+// * Answer the contents of self's destination specification widget
+// *
+// * @return java.lang.String
+// */
+// protected String getDestinationValue() {
+//
+// return fDestinationNamesCombo.getText().trim();
+// }
/**
- * Answer the contents of self's destination specification widget
- *
- * @return java.lang.String
- */
- protected String getDestinationValue() {
- return destinationNameField.getText().trim();
- }
+ * Answer the contents of the destination specification widget. If this
+ * value does not have the required suffix then add it first.
+ *
+ * @return java.lang.String
+ */
+ protected String getDestinationValue() {
+ String destinationText= fDestinationNamesCombo.getText().trim();
+ if (destinationText.indexOf('.') < 0)
+ destinationText += getOutputSuffix();
+ return destinationText;
+ }
+
+ /**
+ * Answer the suffix that files exported from this wizard must have.
+ * If this suffix is a file extension (which is typically the case)
+ * then it must include the leading period character.
+ *
+ * @return java.lang.String
+ */
+ protected String getOutputSuffix() {
+ return ".pdf"; //$NON-NLS-1$
+ }
/**
* Set the contents of the receivers destination specification widget to the passed value
*
*/
protected void setDestinationValue(String value) {
- destinationNameField.setText(value);
+ fDestinationNamesCombo.setText(value);
}
/**
* Hook method for saving widget values for restoration by the next instance of this class.
*/
protected void internalSaveWidgetValues() {
- // update directory names history
- IDialogSettings settings = getDialogSettings();
- if (settings != null) {
- String[] directoryNames = settings.getArray(STORE_DESTINATION_NAMES_ID);
- if (directoryNames == null)
- directoryNames = new String[0];
-
- directoryNames = addToHistory(directoryNames, getDestinationValue());
- settings.put(STORE_DESTINATION_NAMES_ID, directoryNames);
-
- // options
- settings.put(STORE_OVERWRITE_EXISTING_FILES_ID, overwriteExistingFilesCheckbox.getSelection());
-
- // settings.put(
- // STORE_CREATE_STRUCTURE_ID,
- // createDirectoryStructureButton.getSelection());
-
- }
+
}
/**
+ * Persists resource specification control setting that are to be restored
+ * in the next instance of this page. Subclasses wishing to persist
+ * settings for their controls should extend the hook method
+ * <code>internalSaveWidgetValues</code>.
+ */
+ public final void saveWidgetValues() {
+ // update directory names history
+ IDialogSettings settings= getDialogSettings();
+ if (settings != null) {
+ String[] directoryNames= settings.getArray(STORE_DESTINATION_NAMES);
+ if (directoryNames == null)
+ directoryNames= new String[0];
+ directoryNames= addToHistory(directoryNames, getDestinationValue());
+ settings.put(STORE_DESTINATION_NAMES, directoryNames);
+
+ // options
+ settings.put(STORE_OVERWRITE_EXISTING_FILES_ID, overwriteExistingFilesCheckbox.getSelection());
+ }
+ // Allow subclasses to save values
+ internalSaveWidgetValues();
+ }
+
+ /**
* Hook method for restoring widget values to the values that they held last time this wizard was used to completion.
*/
protected void restoreWidgetValues() {
IDialogSettings settings = getDialogSettings();
if (settings != null) {
- String[] directoryNames = settings.getArray(STORE_DESTINATION_NAMES_ID);
- if (directoryNames == null)
+ String[] fileNames = settings.getArray(STORE_DESTINATION_NAMES);
+ if (fileNames == null)
return; // ie.- no settings stored
// destination
- setDestinationValue(directoryNames[0]);
- for (int i = 0; i < directoryNames.length; i++)
- addDestinationItem(directoryNames[i]);
+ setDestinationValue(fileNames[0]);
+ for (int i = 0; i < fileNames.length; i++)
+ addDestinationItem(fileNames[i]);
// options
overwriteExistingFilesCheckbox.setSelection(settings.getBoolean(STORE_OVERWRITE_EXISTING_FILES_ID));
// createSelectionOnlyButton.setSelection(!createDirectories);
}
}
+
/**
- * Add the passed value to self's destination widget's history
- *
- * @param value java.lang.String
- */
- protected void addDestinationItem(String value) {
- destinationNameField.add(value);
- }
+ * Add the passed value to self's destination widget's history
+ *
+ * @param value
+ * java.lang.String
+ */
+ protected void addDestinationItem(String value) {
+ fDestinationNamesCombo.add(value);
+ }
+
/**
* (non-Javadoc) Method declared on IDialogPage.
*/
public void createControl(Composite parent) {
super.createControl(parent);
+// update();
giveFocusToDestination();
// WorkbenchHelp.setHelp(
// getControl(),
* Set the current input focus to self's destination entry field
*/
protected void giveFocusToDestination() {
- destinationNameField.setFocus();
+ fDestinationNamesCombo.setFocus();
}
// private Composite createControlsContainer(Composite parent) {
// return editor;
// }
- private void initialize() throws CoreException {
- if (selection == null || selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
- return;
- }
-
- IStructuredSelection ssel = (IStructuredSelection) selection;
- if (ssel.size() == 1) {
- initialiseFromSelectedObject(ssel.getFirstElement());
- }
- }
-
- private void initialiseFromSelectedObject(Object obj) throws CoreException {
- if (obj instanceof IFolder || obj instanceof IProject) {
- initialiseFolder(((IResource) obj));
- }
- }
-
- private void initialiseFolder(IResource resource) throws CoreException {
- folderText.setStringValue(resource.getFullPath().toString());
- initialiseExportDirectoryText(resource);
- }
-
- private void initialiseExportDirectoryText(IResource resource) throws CoreException {
- String exportDir = resource.getProject().getPersistentProperty(WikiPDFExportWizard.DIRECTORY_QUALIFIED_NAME);
- if (exportDir != null) {
- exportFileText.setStringValue(exportDir);
- } else {
- exportFileText.setStringValue("");
- }
- }
-
- private void handleBrowseHtmlExportLocation() {
- FileDialog dialog = new FileDialog(getShell(), SWT.SINGLE | SWT.OPEN);
- dialog.setFilterExtensions(PDF_EXTENSION);
- String path = dialog.open();
- if (path != null) {
- exportFileText.setStringValue(path);
- }
- }
-
- private void handleBrowseFolders() throws CoreException {
- ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), false,
- WikiEditorPlugin.getResourceString("Export.wizardSelectFolder"));
- if (dialog.open() == Window.OK) {
- Object[] result = dialog.getResult();
- if (result != null && result.length == 1) {
- IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember((IPath) result[0]);
- if (resource instanceof IFile) {
- return;
- }
- initialiseFolder(resource);
- }
- }
- }
-
+// private void initialize() throws CoreException {
+// if (fInitialSelection == null || fInitialSelection.isEmpty() || !(fInitialSelection instanceof IStructuredSelection)) {
+// return;
+// }
+//
+// IStructuredSelection ssel = (IStructuredSelection) fInitialSelection;
+// if (ssel.size() == 1) {
+// initialiseFromSelectedObject(ssel.getFirstElement());
+// }
+// }
+
+// private void initialiseFromSelectedObject(Object obj) throws CoreException {
+// if (obj instanceof IFolder || obj instanceof IProject) {
+// initialiseFolder(((IResource) obj));
+// }
+// }
+
+// private void initialiseFolder(IResource resource) throws CoreException {
+// folderText.setStringValue(resource.getFullPath().toString());
+// initialiseExportDirectoryText(resource);
+// }
+
+// private void initialiseExportDirectoryText(IResource resource) throws CoreException {
+// String exportDir = resource.getProject().getPersistentProperty(WikiPDFExportWizard.DIRECTORY_QUALIFIED_NAME);
+// if (exportDir != null) {
+// exportFileText.setStringValue(exportDir);
+// } else {
+// exportFileText.setStringValue("");
+// }
+// }
+
+// private void handleBrowseHtmlExportLocation() {
+// FileDialog dialog = new FileDialog(getShell(), SWT.SINGLE | SWT.OPEN);
+// dialog.setFilterExtensions(PDF_EXTENSION);
+// String path = dialog.open();
+// if (path != null) {
+// setDestinationValue(path);
+//// exportFileText.setStringValue(path);
+// }
+// }
+//
+// private void handleBrowseFolders() throws CoreException {
+// FileDialog dialog = new FileDialog(getShell());
+// //, ResourcesPlugin.getWorkspace().getRoot(), false,
+// // WikiEditorPlugin.getResourceString("Export.wizardSelectFolder"));
+// String filePath = dialog.open();
+// // if (dialog.open() == Window.OK) {
+// // Object[] result = dialog.getResult();
+// if (filePath != null) {
+// // if (result != null && result.length == 1) {
+// // IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember((IPath) result[0]);
+// IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(filePath);
+// if (!(resource instanceof IFile)) {
+// return;
+// }
+//// initialiseFolder(resource);
+// // }
+// }
+// }
+
+
private void dialogChanged() {
- if (getFolderText().length() == 0) {
- updateStatus("Folder must be specified");
- } else if (getExportDirectoryPath().length() == 0) {
- updateStatus("Directory must be specified");
+// if (getFolderText().length() == 0) {
+// updateStatus("File must be specified");
+// } else
+
+ if (getDestinationValue().length() == 0) {
+ updateStatus("PDF export file must be specified");
} else {
updateStatus(null);
}
setPageComplete(message == null);
}
- public String getExportDirectoryPath() {
- return exportFileText.getStringValue();
- }
+// public String getExportDirectoryPath() {
+// return exportFileText.getStringValue();
+// }
public void propertyChange(PropertyChangeEvent event) {
dialogChanged();
dialogChanged();
}
- String getFolderText() {
- return folderText.getStringValue();
- }
+// String getFolderText() {
+// return folderText.getStringValue();
+// }
- public IContainer getFolder() {
- return (IContainer) ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getFolderText()));
+ public IContainer getFile() {
+ return (IContainer) ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getDestinationValue()));
}
protected boolean executeExportOperation(WikiPDFExporter op) {
return false;
}
+
+ /**
+ * Returns a boolean indicating whether the passed File handle is
+ * is valid and available for use.
+ *
+ * @return boolean
+ */
+// protected boolean ensureTargetFileIsValid(File targetFile) {
+// if (targetFile.exists() && targetFile.isDirectory() && fDestinationNamesCombo.getText().length() > 0) {
+// setErrorMessage(JarPackagerMessages.getString("JarPackageWizardPage.error.exportDestinationMustNotBeDirectory")); //$NON-NLS-1$
+// fDestinationNamesCombo.setFocus();
+// return false;
+// }
+// if (targetFile.exists()) {
+// if (!targetFile.canWrite()) {
+// setErrorMessage(JarPackagerMessages.getString("JarPackageWizardPage.error.jarFileExistsAndNotWritable")); //$NON-NLS-1$
+// fDestinationNamesCombo.setFocus();
+// return false;
+// }
+// }
+// return true;
+// }
+
}
\ No newline at end of file