Search in sources :

Example 36 with FileDialog

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

the class PublishOnSpagoExportWizardPage method handleDestinationBrowseButtonPressed.

/**
     * Open an appropriate destination browser so that the user can specify a source to import from.
     */
protected void handleDestinationBrowseButtonPressed() {
    FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.SAVE);
    //$NON-NLS-1$ //$NON-NLS-2$
    dialog.setFilterExtensions(new String[] { "*.zip", "*.*" });
    //$NON-NLS-1$
    dialog.setText("");
    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) {
        setErrorMessage(null);
        setDestinationValue(selectedFileName);
    }
}
Also used : FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 37 with FileDialog

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

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

the class ExpressionBuilderDialog method createButtonsForButtonBar.

/**
     * Create contents of the button bar
     * 
     * @param parent
     */
@Override
protected void createButtonsForButtonBar(Composite parent) {
    ((GridLayout) parent.getLayout()).numColumns++;
    Composite buttons = new Composite(parent, SWT.NONE);
    buttons.setLayout(new GridLayout(2, false));
    final Button importButton = new Button(buttons, SWT.PUSH);
    //$NON-NLS-1$
    importButton.setToolTipText(Messages.getString("ExpressionBuilderDialog.import"));
    importButton.setImage(ImageProvider.getImage(EImage.IMPORT_ICON));
    final Button exportButton = new Button(buttons, SWT.PUSH);
    //$NON-NLS-1$
    exportButton.setToolTipText(Messages.getString("ExpressionBuilderDialog.export"));
    exportButton.setImage(ImageProvider.getImage(EImage.EXPORT_ICON));
    //$NON-NLS-1$
    createButton(parent, IDialogConstants.OK_ID, Messages.getString("ExpressionBuilderDialog.ok.button"), true);
    //$NON-NLS-1$
    createButton(parent, IDialogConstants.CANCEL_ID, Messages.getString("ExpressionBuilderDialog.cancel.button"), false);
    exportButton.addMouseListener(new MouseAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
             */
        @Override
        public void mouseUp(MouseEvent e) {
            FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
            //$NON-NLS-1$
            dialog.setFilterExtensions(new String[] { "*.xml" });
            String filePath = dialog.open();
            if (filePath != null) {
                String expresionContent = expressionComposite.getExpression();
                List<Variable> variables = new ArrayList<Variable>();
                variables = testComposite.getVariableList();
                File file = new File(filePath);
                ExpressionFileOperation operation = new ExpressionFileOperation();
                try {
                    if (file != null) {
                        file.createNewFile();
                    }
                    operation.saveExpressionToFile(file, variables, expresionContent);
                } catch (IOException e1) {
                    RuntimeExceptionHandler.process(e1);
                } catch (ParserConfigurationException e1) {
                    RuntimeExceptionHandler.process(e1);
                }
            }
        }
    });
    importButton.addMouseListener(new MouseAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
             */
        @Override
        public void mouseUp(MouseEvent e) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
            //$NON-NLS-1$
            dialog.setFilterExtensions(new String[] { "*.xml" });
            String filePath = dialog.open();
            if (filePath != null) {
                File file = new File(filePath);
                ExpressionFileOperation operation = new ExpressionFileOperation();
                try {
                    List list = operation.importExpressionFromFile(file, getShell());
                    if (list != null && list.size() != 0) {
                        expressionComposite.setExpression((String) list.get(0), false);
                        list.remove(0);
                        if (list.size() > 0) {
                            testComposite.addVariables(list);
                        }
                    }
                } catch (IOException e1) {
                    RuntimeExceptionHandler.process(e1);
                } catch (ParserConfigurationException e1) {
                    RuntimeExceptionHandler.process(e1);
                } catch (SAXException e1) {
                    RuntimeExceptionHandler.process(e1);
                }
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) ExpressionFileOperation(org.talend.expressionbuilder.ExpressionFileOperation) Composite(org.eclipse.swt.widgets.Composite) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ArrayList(java.util.ArrayList) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 39 with FileDialog

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

the class ConfigureConnParamDialog method createFileComponent.

/**
     * qiang.zhang Comment method "createFileComponent".
     * 
     * @param key
     * @param defaultContext
     */
private void createFileComponent(final EConnectionParameterName key, IContext defaultContext) {
    GridLayout gridLayout;
    GridData gridData;
    Composite hostComposite = new Composite(mainComposite, SWT.NONE);
    gridLayout = new GridLayout();
    gridLayout.verticalSpacing = 2;
    gridLayout.marginTop = 5;
    gridLayout.marginBottom = 2;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    gridLayout.marginLeft = 0;
    gridLayout.marginRight = 0;
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    hostComposite.setLayout(gridLayout);
    hostComposite.setLayoutData(gridData);
    Label hostLabel = new Label(hostComposite, SWT.NONE);
    //$NON-NLS-1$
    hostLabel.setText(key.getDisplayName() + ":");
    // GridDataFactory.swtDefaults().hint(LABEL_DEFAULT_X, DEFAULT_HEIGHT).applyTo(hostLabel);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    hostLabel.setLayoutData(data);
    Composite fileComposite = new Composite(hostComposite, SWT.NONE);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    gridLayout.verticalSpacing = 0;
    gridLayout.marginTop = 0;
    gridLayout.marginBottom = 0;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    gridLayout.marginLeft = 0;
    gridLayout.marginRight = 0;
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    fileComposite.setLayout(gridLayout);
    fileComposite.setLayoutData(gridData);
    final Text host = new Text(fileComposite, SWT.BORDER);
    host.setText(pvValues.get(key));
    if (host.getText().trim().length() == 0) {
        host.setBackground(ColorConstants.red);
        host.redraw();
    }
    // GridDataFactory.swtDefaults().hint(TEXT_DEFAULT_X, DEFAULT_HEIGHT).applyTo(host);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    host.setLayoutData(gridData);
    Button button = new Button(fileComposite, SWT.PUSH);
    //$NON-NLS-1$
    button.setText("...");
    button.addSelectionListener(new SelectionListener() {

        /*
             * (non-Javadoc)
             * 
             * @see
             * org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
             */
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
             */
        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(mainComposite.getShell(), SWT.NONE);
            String path = PathExtractor.extractPath(host.getText());
            dialog.setFileName(PathUtils.getOSPath(path));
            String file = dialog.open();
            if (file != null) {
                if (!file.equals("")) {
                    //$NON-NLS-1$
                    host.setText(PathUtils.getPortablePath(file));
                }
            }
        }
    });
    final Text hostText = new Text(hostComposite, SWT.NONE);
    hostText.setEditable(false);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    hostText.setLayoutData(gridData);
    hostText.setText(CONTEXT_WITH + ContextParameterUtils.parseScriptContextCode(host.getText(), defaultContext));
    host.setData(TEXT_CONTROL, hostText);
    host.setData(key);
    allParamText.add(host);
    host.addModifyListener(new ModifyListener() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
             */
        @Override
        public void modifyText(ModifyEvent e) {
            if (isRequriedValue(key.getName())) {
                if (host.getText().trim().length() == 0) {
                    host.setBackground(ColorConstants.red);
                    host.redraw();
                } else {
                    host.setBackground(ColorConstants.white);
                    host.redraw();
                }
                resetValues(host, hostText);
            }
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) 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) FileDialog(org.eclipse.swt.widgets.FileDialog) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 40 with FileDialog

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

the class ImportHL7StructureAction method treeNodeAdapt.

private List treeNodeAdapt() {
    List<HL7TreeNode> treeData = new ArrayList<HL7TreeNode>();
    FileDialog f = null;
    if (hl7ui != null) {
        f = new FileDialog(hl7ui.getHl7UIParent().getShell());
    } else if (form != null) {
        f = new FileDialog(form.getShell());
    }
    String file = f.open();
    if (file == null) {
        return treeData;
    }
    HL7Parse hl7Parse = new HL7Parse();
    List<String> msgContentList = new ArrayList<String>();
    List<Message> messageList = hl7Parse.doParse(file, "'\\u000b'", "'\\u001c'");
    List<HL7TreeNode> nodeList = hl7Util.getHL7TreeNodes(messageList);
    if (!nodeList.isEmpty()) {
        HL7TreeNode hl7TreeNode = nodeList.get(0);
        List<HL7FileNode> table = new ArrayList<HL7FileNode>();
        if (hl7Connection != null) {
            EList root = hl7Connection.getRoot();
            root.clear();
            if (hl7TreeNode != null) {
                hl7Util.initNodeOrder(hl7TreeNode, orderMap);
                hl7Util.tableLoader((Element) hl7TreeNode, "", root, hl7TreeNode.getDefaultValue(), orderMap);
            }
            table.addAll(root);
        } else {
            if (hl7TreeNode != null) {
                hl7Util.initNodeOrder(hl7TreeNode, orderMap);
                hl7Util.tableLoader((Element) hl7TreeNode, "", table, hl7TreeNode.getDefaultValue(), orderMap);
            }
        }
        List<String> schemaList = new ArrayList<String>();
        for (HL7FileNode node : table) {
            String columnName = node.getRelatedColumn();
            if (columnName.contains(":")) {
                columnName = columnName.substring(0, columnName.indexOf(":"));
            }
            if (!schemaList.contains(columnName) && !"".equals(columnName)) {
                schemaList.add(columnName);
            }
        }
        initXmlTreeData(schemaList, table, treeData);
    }
    return treeData;
}
Also used : EList(org.eclipse.emf.common.util.EList) Message(ca.uhn.hl7v2.model.Message) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) ArrayList(java.util.ArrayList) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) FileDialog(org.eclipse.swt.widgets.FileDialog) HL7Parse(org.talend.designer.hl7.ui.header.HL7Parse)

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