Search in sources :

Example 31 with IDialogSettings

use of org.eclipse.jface.dialogs.IDialogSettings in project tesb-studio-se by Talend.

the class JavaCamelJobScriptsExportWSWizardPage method handleDestinationBrowseButtonPressed.

/**
     * Open an appropriate destination browser so that the user can specify a source to import from.
     */
@Override
protected void handleDestinationBrowseButtonPressed() {
    FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.SAVE);
    if (isAddMavenScript()) {
        //$NON-NLS-1$ //$NON-NLS-2$
        dialog.setFilterExtensions(new String[] { "*" + FileConstants.ZIP_FILE_SUFFIX, "*.*" });
    } else if (EXPORTTYPE_SPRING_BOOT.equals(exportTypeCombo.getText())) {
        if (exportAsZip || isAddMavenScript()) {
            //$NON-NLS-1$ //$NON-NLS-2$
            dialog.setFilterExtensions(new String[] { "*" + FileConstants.ZIP_FILE_SUFFIX, "*.*" });
        } else {
            //$NON-NLS-1$ //$NON-NLS-2$
            dialog.setFilterExtensions(new String[] { "*.jar", "*.*" });
        }
    } else {
        //$NON-NLS-1$ //$NON-NLS-2$
        dialog.setFilterExtensions(new String[] { "*.kar", "*.*" });
    }
    //$NON-NLS-1$
    dialog.setText("");
    // this is changed by me shenhaize
    dialog.setFileName(this.getDefaultFileName().get(0));
    String currentSourceString = getDestinationValue();
    int lastSeparatorIndex = currentSourceString.lastIndexOf(File.separator);
    if (lastSeparatorIndex != -1) {
        dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex));
    }
    String selectedFileName = dialog.open();
    if (selectedFileName == null) {
        return;
    }
    String idealSuffix;
    if (isAddMavenScript()) {
        idealSuffix = FileConstants.ZIP_FILE_SUFFIX;
    } else if (EXPORTTYPE_SPRING_BOOT.equals(exportTypeCombo.getText())) {
        if (exportAsZip || isAddMavenScript()) {
            idealSuffix = FileConstants.ZIP_FILE_SUFFIX;
        } else {
            idealSuffix = FileConstants.JAR_FILE_SUFFIX;
        }
    } else {
        idealSuffix = getOutputSuffix();
    }
    if (!selectedFileName.endsWith(idealSuffix)) {
        selectedFileName += idealSuffix;
    }
    // when user change the name of job,will add the version auto
    if (selectedFileName != null && !selectedFileName.endsWith(this.getSelectedJobVersion() + idealSuffix)) {
        String b = selectedFileName.substring(0, (selectedFileName.length() - 4));
        File file = new File(b);
        String str = file.getName();
        String s = this.getDefaultFileName().get(0);
        if (str.equals(s)) {
            //$NON-NLS-1$
            selectedFileName = b + "_" + this.getDefaultFileName().get(1) + idealSuffix;
        } else {
            selectedFileName = b + idealSuffix;
        }
    }
    if (selectedFileName != null) {
        setErrorMessage(null);
        setDestinationValue(selectedFileName);
        if (getDialogSettings() != null) {
            IDialogSettings section = getDialogSettings().getSection(DESTINATION_FILE);
            if (section == null) {
                section = getDialogSettings().addNewSection(DESTINATION_FILE);
            }
            section.put(DESTINATION_FILE, selectedFileName);
        }
    }
}
Also used : IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 32 with IDialogSettings

use of org.eclipse.jface.dialogs.IDialogSettings in project tesb-studio-se by Talend.

the class JavaCamelJobScriptsExportWSWizardPage method internalSaveWidgetValues.

/**
     * Hook method for saving widget values for restoration by the next instance of this class.
     */
@Override
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);
    }
}
Also used : IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings)

Example 33 with IDialogSettings

use of org.eclipse.jface.dialogs.IDialogSettings in project tesb-studio-se by Talend.

the class JavaCamelJobScriptsExportWSWizardPage method restoreWidgetValues.

// @Override
// protected void internalSaveWidgetValues() {
// // update directory names history
// IDialogSettings settings = getDialogSettings();
// if (settings != null) {
// String[] directoryNames = new String[1];
// String destinationValue = manager.getDestinationPath();
// if (destinationValue != null) {
// IPath path = Path.fromOSString(destinationValue);
// destinationValue = path.removeLastSegments(1).toOSString();
// }
// directoryNames[0] = destinationValue;
//
// settings.put(STORE_DESTINATION_NAMES_ID, directoryNames);
// }
// }
/**
     * Hook method for restoring widget values to the values that they held last time this wizard was used to
     * completion.
     */
@Override
protected void restoreWidgetValues() {
    IDialogSettings settings = getDialogSettings();
    if (settings != null) {
        String[] directoryNames = settings.getArray(STORE_DESTINATION_NAMES_ID);
        if (directoryNames != null && directoryNames.length > 0) {
            for (String directoryName : directoryNames) {
                addDestinationItem(directoryName);
            }
        }
        setDefaultDestination();
    }
}
Also used : IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings)

Example 34 with IDialogSettings

use of org.eclipse.jface.dialogs.IDialogSettings in project tdi-studio-se by Talend.

the class JavaJobScriptsExportWSWizardPage method handleDestinationBrowseButtonPressed.

/**
     * Open an appropriate destination browser so that the user can specify a source to import from.
     */
@Override
protected void handleDestinationBrowseButtonPressed() {
    FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.SAVE);
    JobExportType jobExportType = getCurrentExportType1();
    switch(jobExportType) {
        case WSWAR:
            //$NON-NLS-1$ //$NON-NLS-2$
            dialog.setFilterExtensions(new String[] { "*" + FileConstants.WAR_FILE_SUFFIX, "*.*" });
            break;
        case OSGI:
            if (isAddMavenScript()) {
                //$NON-NLS-1$ //$NON-NLS-2$
                dialog.setFilterExtensions(new String[] { "*" + FileConstants.ZIP_FILE_SUFFIX, "*.*" });
            } else {
                //$NON-NLS-1$ //$NON-NLS-2$
                dialog.setFilterExtensions(new String[] { "*" + FileConstants.JAR_FILE_SUFFIX, "*.*" });
            }
            break;
        default:
            //$NON-NLS-1$ //$NON-NLS-2$
            dialog.setFilterExtensions(new String[] { "*" + FileConstants.ZIP_FILE_SUFFIX, "*.*" });
    }
    //$NON-NLS-1$
    dialog.setText("");
    // this is changed by me shenhaize
    dialog.setFileName(getDefaultFileName().get(0));
    String currentSourceString = getDestinationValue();
    int lastSeparatorIndex = currentSourceString.lastIndexOf(File.separator);
    if (lastSeparatorIndex != -1) {
        dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex));
    }
    String selectedFileName = dialog.open();
    if (selectedFileName == null) {
        return;
    }
    String idealSuffix;
    if (isAddMavenScript()) {
        idealSuffix = FileConstants.ZIP_FILE_SUFFIX;
    } else {
        idealSuffix = getOutputSuffix();
    }
    if (!selectedFileName.endsWith(idealSuffix)) {
        selectedFileName += idealSuffix;
    }
    // when user change the name of job,will add the version auto
    if (selectedFileName != null && !selectedFileName.endsWith(getSelectedJobVersion() + idealSuffix)) {
        String b = selectedFileName.substring(0, (selectedFileName.length() - 4));
        File file = new File(b);
        String str = file.getName();
        String s = getDefaultFileName().get(0);
        if (str.equals(s)) {
            if (getDefaultFileName().get(1) != null && !"".equals(getDefaultFileName().get(1))) {
                selectedFileName = b + ((JobExportType.OSGI.equals(jobExportType)) ? "-" : "_") + getDefaultFileName().get(1) + idealSuffix;
            } else {
                selectedFileName = b + idealSuffix;
            }
        } else {
            selectedFileName = b + idealSuffix;
        }
    }
    if (selectedFileName != null) {
        setErrorMessage(null);
        setDestinationValue(selectedFileName);
        if (getDialogSettings() != null) {
            IDialogSettings section = getDialogSettings().getSection(DESTINATION_FILE);
            if (section == null) {
                section = getDialogSettings().addNewSection(DESTINATION_FILE);
            }
            section.put(DESTINATION_FILE, selectedFileName);
        }
    }
}
Also used : IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 35 with IDialogSettings

use of org.eclipse.jface.dialogs.IDialogSettings in project tdi-studio-se by Talend.

the class JavaJobScriptsExportWSWizardPage method restoreWidgetValuesForPetalsESB.

protected void restoreWidgetValuesForPetalsESB() {
    IDialogSettings settings = getDialogSettings();
    if (settings != null) {
        String[] directoryNames = settings.getArray(STORE_DESTINATION_NAMES_ID);
        String saName = getPetalsDefaultSaName();
        if (directoryNames != null && directoryNames.length > 0) {
            // destination
            for (int i = 0; i < directoryNames.length; i++) {
                if (directoryNames[i].toLowerCase().endsWith(FileConstants.ZIP_FILE_SUFFIX)) {
                    //$NON-NLS-1$
                    directoryNames[i] = (directoryNames[i].charAt(0) + "").toUpperCase() + directoryNames[i].substring(1);
                    addDestinationItem(directoryNames[i]);
                }
            }
            File file = new File(directoryNames[0]);
            File dest = new File(file.getParentFile(), saName);
            setDestinationValue(dest.getAbsolutePath());
        } else {
            //$NON-NLS-1$
            String userDir = System.getProperty("user.dir");
            IPath path = new Path(userDir).append(saName);
            setDestinationValue(path.toOSString());
        }
        sourceButton.setSelection(settings.getBoolean(STORE_SOURCE_ID));
        // Do not extract the ZIP //$NON-NLS-1$
        zipOption = "false";
    }
    if (getProcessItem() != null) {
        List<String> contextNames = ExportJobUtil.getJobContexts(getProcessItem());
        contextCombo.setItems(contextNames.toArray(new String[contextNames.size()]));
        contextCombo.setVisibleItemCount(contextNames.size());
        if (contextNames.size() > 0) {
            contextCombo.select(0);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) File(java.io.File)

Aggregations

IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)81 File (java.io.File)9 ArrayList (java.util.ArrayList)6 PersistenceException (org.talend.commons.exception.PersistenceException)6 Point (org.eclipse.swt.graphics.Point)5 Path (org.eclipse.core.runtime.Path)4 MenuItem (org.eclipse.swt.widgets.MenuItem)4 IPath (org.eclipse.core.runtime.IPath)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 GridData (org.eclipse.swt.layout.GridData)3 Combo (org.eclipse.swt.widgets.Combo)3 Composite (org.eclipse.swt.widgets.Composite)3 FileDialog (org.eclipse.swt.widgets.FileDialog)3 Widget (org.eclipse.swt.widgets.Widget)3 LocalFile (org.eclipse.core.internal.filesystem.local.LocalFile)2 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)2