Search in sources :

Example 31 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project tdi-studio-se by Talend.

the class ExtractDocumentationAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
protected void doRun() {
    RepositoryNode node = (RepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
    final Item item = node.getObject().getProperty().getItem();
    if (item == null) {
        return;
    }
    String initialFileName = null;
    String initialExtension = null;
    if (item instanceof DocumentationItem) {
        DocumentationItem documentationItem = (DocumentationItem) item;
        initialFileName = documentationItem.getName();
        if (documentationItem.getExtension() != null) {
            initialExtension = documentationItem.getExtension();
        }
    } else if (item instanceof LinkDocumentationItem) {
        // link documenation
        LinkDocumentationItem linkDocItem = (LinkDocumentationItem) item;
        if (!LinkUtils.validateLink(linkDocItem.getLink())) {
            MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.getString(//$NON-NLS-1$
            "ExtractDocumentationAction.fileErrorTitle"), //$NON-NLS-1$
            Messages.getString("ExtractDocumentationAction.fileErrorMessages"));
            return;
        }
        initialFileName = linkDocItem.getName();
        if (linkDocItem.getExtension() != null) {
            initialExtension = linkDocItem.getExtension();
        }
    }
    if (initialFileName != null) {
        FileDialog fileDlg = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
        if (initialExtension != null) {
            //$NON-NLS-1$
            initialFileName = initialFileName + LinkUtils.DOT + initialExtension;
            //$NON-NLS-1$ //$NON-NLS-2$
            fileDlg.setFilterExtensions(new String[] { "*." + initialExtension, "*.*" });
        }
        fileDlg.setFileName(initialFileName);
        String filename = fileDlg.open();
        if (filename != null) {
            final File file = new File(filename);
            ProgressDialog progressDialog = new ProgressDialog(Display.getCurrent().getActiveShell()) {

                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    try {
                        if (item instanceof DocumentationItem) {
                            DocumentationItem documentationItem = (DocumentationItem) item;
                            documentationItem.getContent().setInnerContentToFile(file);
                        } else if (item instanceof LinkDocumentationItem) {
                            // link documenation
                            LinkDocumentationItem linkDocItem = (LinkDocumentationItem) item;
                            ByteArray byteArray = LinkDocumentationHelper.getLinkItemContent(linkDocItem);
                            if (byteArray != null) {
                                byteArray.setInnerContentToFile(file);
                            }
                        }
                    } catch (IOException ioe) {
                        MessageBoxExceptionHandler.process(ioe);
                    }
                }
            };
            try {
                progressDialog.executeProcess();
            } catch (InvocationTargetException e) {
                ExceptionHandler.process(e);
            } catch (InterruptedException e) {
            // Nothing to do
            }
        }
    }
}
Also used : LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) IOException(java.io.IOException) RepositoryNode(org.talend.repository.model.RepositoryNode) BinRepositoryNode(org.talend.repository.model.BinRepositoryNode) DocumentationItem(org.talend.core.model.properties.DocumentationItem) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Item(org.talend.core.model.properties.Item) DocumentationItem(org.talend.core.model.properties.DocumentationItem) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ByteArray(org.talend.core.model.properties.ByteArray) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 32 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project tdi-studio-se by Talend.

the class PromptDialog method createParameterComposite.

/**
     * DOC qiang.zhang Comment method "createParameterComposite".
     * 
     * @param parent
     * @param parameter
     * @param label
     */
private void createParameterComposite(final Composite parent, final IContextParameter parameter, Label label) {
    final Composite child = new Composite(parent, SWT.NONE);
    final GridLayout layout = new GridLayout(2, false);
    layout.marginLeft = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    child.setLayout(layout);
    child.setLayoutData(new GridData(GridData.FILL_BOTH));
    if (DefaultCellEditorFactory.isList(parameter.getType())) {
        createListParameterArea(parameter, label, child);
        return;
    }
    final Text text = new Text(child, SWT.SINGLE | SWT.BORDER);
    text.setText(parameter.getValue());
    text.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            parameter.setValue(text.getText());
        }
    });
    //$NON-NLS-1$
    String stringTip = "";
    //$NON-NLS-1$
    String comment = "";
    if (parameter.getType().equalsIgnoreCase("String") && LanguageManager.getCurrentLanguage() == ECodeLanguage.PERL) {
        //$NON-NLS-1$
        //$NON-NLS-1$
        stringTip = Messages.getString("PromptDialog.stringTip");
    }
    comment = parameter.getComment();
    if (!stringTip.equals("")) {
        //$NON-NLS-1$
        //$NON-NLS-1$
        comment = comment + " " + stringTip;
    }
    label.setToolTipText(comment);
    text.setToolTipText(comment);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.minimumWidth = MINIMUM_WIDTH;
    text.setLayoutData(data);
    if (DefaultCellEditorFactory.isDate(parameter.getType())) {
        text.setEditable(false);
        final Button b = new Button(child, SWT.NONE);
        //$NON-NLS-1$
        b.setText("...");
        b.addSelectionListener(new SelectionAdapter() {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
                 */
            @Override
            public void widgetSelected(SelectionEvent e) {
                DateDialog d = new DateDialog(((Button) e.getSource()).getShell());
                int res = d.open();
                if (res == Dialog.OK) {
                    text.setText(DefaultCellEditorFactory.getAddQuoteString(d.getTalendDateString()));
                }
            }
        });
    } else if (DefaultCellEditorFactory.isFile(parameter.getType())) {
        text.setEditable(false);
        final Button b = new Button(child, SWT.NONE);
        //$NON-NLS-1$
        b.setText("...");
        b.addSelectionListener(new SelectionAdapter() {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
                 */
            @Override
            public void widgetSelected(SelectionEvent e) {
                FileDialog d = new FileDialog(((Button) e.getSource()).getShell());
                if (text.getText() != null) {
                    d.setFileName(PathUtils.getOSPath(DefaultCellEditorFactory.getRemoveQuoteString(text.getText())));
                }
                String open = d.open();
                if (open != null) {
                    text.setText(DefaultCellEditorFactory.getAddQuoteString(PathUtils.getPortablePath(open)));
                }
            }
        });
    } else if (DefaultCellEditorFactory.isDirectory(parameter.getType())) {
        text.setEditable(false);
        final Button b = new Button(child, SWT.NONE);
        //$NON-NLS-1$
        b.setText("...");
        b.addSelectionListener(new SelectionAdapter() {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
                 */
            @Override
            public void widgetSelected(SelectionEvent e) {
                DirectoryDialog d = new DirectoryDialog(((Button) e.getSource()).getShell());
                if (text.getText() != null) {
                    d.setFilterPath(PathUtils.getOSPath(DefaultCellEditorFactory.getRemoveQuoteString(text.getText())));
                }
                String open = d.open();
                if (open != null) {
                    open = PathUtils.getPortablePath(open);
                    //$NON-NLS-1$
                    open += "/";
                    text.setText(DefaultCellEditorFactory.getAddQuoteString(open));
                }
            }
        });
    } else if (DefaultCellEditorFactory.isPassword(parameter.getType())) {
        text.setEchoChar('*');
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DateDialog(org.talend.commons.ui.runtime.swt.tableviewer.celleditor.DateDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 33 with FileDialog

use of org.eclipse.swt.widgets.FileDialog 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 34 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project tdi-studio-se by Talend.

the class ExportXLSAction method run.

/**
     * Copy all table data to clipboard.
     * 
     * @see org.eclipse.jface.action.IAction#run()
     */
public void run() {
    FileDialog fileDialog = new FileDialog(ptable.getShell(), SWT.SAVE);
    //$NON-NLS-1$
    String[] filterExtensions = new String[] { "*.xls" };
    fileDialog.setFilterExtensions(filterExtensions);
    final String fileName = fileDialog.open();
    if (fileName == null || fileName.trim().length() == 0) {
        return;
    }
    BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

        public void run() {
            try {
                File file = new File(fileName);
                if (file.exists()) {
                    // overwrite existing files
                    file.delete();
                }
                file.createNewFile();
                BufferedWriter writer = new BufferedWriter(new FileWriter(file));
                //$NON-NLS-1$
                StringBuffer buffer = new StringBuffer("");
                // get preferences
                boolean includeColumnNames = SqlBuilderPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.CLIP_EXPORT_COLUMNS);
                TableItem[] items = ptable.getItems();
                DataSet dataSet = (DataSet) ptable.getData();
                if (items == null || dataSet == null) {
                    return;
                }
                //$NON-NLS-1$
                writer.write("<table>");
                writer.newLine();
                // export column names
                if (includeColumnNames) {
                    //$NON-NLS-1$
                    buffer.append("<tr>");
                    String[] columnNames = dataSet.getColumnLabels();
                    for (int i = 0; i < columnNames.length; i++) {
                        //$NON-NLS-1$
                        buffer.append("<th>");
                        buffer.append(columnNames[i]);
                        //$NON-NLS-1$
                        buffer.append("</th>");
                    }
                    //$NON-NLS-1$
                    buffer.append("</tr>");
                    writer.write(buffer.toString());
                    writer.newLine();
                }
                // export column data
                int columnCount = ptable.getColumnCount();
                for (int i = 0; i < items.length; i++) {
                    //$NON-NLS-1$
                    buffer = new StringBuffer("<tr>");
                    for (int j = 0; j < columnCount; j++) {
                        //$NON-NLS-1$
                        buffer.append("<td>");
                        buffer.append(items[i].getText(j));
                        //$NON-NLS-1$
                        buffer.append("</td>");
                    }
                    //$NON-NLS-1$
                    buffer.append("</tr>");
                    writer.write(buffer.toString());
                    writer.newLine();
                }
                //$NON-NLS-1$
                writer.write("</table>");
                writer.newLine();
                writer.close();
            } catch (final Exception e) {
                ptable.getShell().getDisplay().asyncExec(new Runnable() {

                    public void run() {
                        MessageDialog.openError(ptable.getShell(), Messages.getString("SQLResultsView.Error.Export.Title"), //$NON-NLS-1$
                        e.getMessage());
                        //$NON-NLS-1$
                        SqlBuilderPlugin.log(Messages.getString("SQLResultsView.Error.Export.Title"), e);
                    }
                });
            }
        }
    });
}
Also used : DataSet(net.sourceforge.sqlexplorer.dataset.DataSet) FileWriter(java.io.FileWriter) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 35 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project tdi-studio-se by Talend.

the class OpenFileAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.sqlbuilder.actions.AbstractEditorAction#run()
     */
public void run() {
    FileDialog dlg = new FileDialog(editor.getShell(), SWT.OPEN | SWT.MULTI);
    //$NON-NLS-1$
    dlg.setFilterExtensions(new String[] { "*.sql;*.txt;*.*" });
    String path = dlg.open();
    if (path != null) {
        String[] files = dlg.getFileNames();
        loadFiles(files, dlg.getFilterPath());
    }
}
Also used : FileDialog(org.eclipse.swt.widgets.FileDialog)

Aggregations

FileDialog (org.eclipse.swt.widgets.FileDialog)214 File (java.io.File)91 Button (org.eclipse.swt.widgets.Button)61 SelectionEvent (org.eclipse.swt.events.SelectionEvent)58 GridLayout (org.eclipse.swt.layout.GridLayout)57 GridData (org.eclipse.swt.layout.GridData)56 Composite (org.eclipse.swt.widgets.Composite)55 Text (org.eclipse.swt.widgets.Text)50 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)48 Label (org.eclipse.swt.widgets.Label)47 IOException (java.io.IOException)31 Group (org.eclipse.swt.widgets.Group)24 Shell (org.eclipse.swt.widgets.Shell)23 ModifyListener (org.eclipse.swt.events.ModifyListener)21 ArrayList (java.util.ArrayList)19 ModifyEvent (org.eclipse.swt.events.ModifyEvent)19 IPath (org.eclipse.core.runtime.IPath)18 Path (org.eclipse.core.runtime.Path)16 Combo (org.eclipse.swt.widgets.Combo)16 SelectionListener (org.eclipse.swt.events.SelectionListener)15