Search in sources :

Example 41 with FileDialog

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

the class ExportItemWizardPage method handleLocationArchiveButtonPressed.

/**
     * The browse button has been selected. Select the location.
     */
protected void handleLocationArchiveButtonPressed() {
    FileDialog dialog = new FileDialog(archivePathField.getShell(), SWT.SAVE);
    dialog.setFilterExtensions(FILE_EXPORT_MASK);
    // dialog.setText(DataTransferMessages.ArchiveExport_selectDestinationTitle);
    //$NON-NLS-1$
    dialog.setText(Messages.getString("DataTransferMessages.ArchiveExport_selectDestinationTitle"));
    String fileName = archivePathField.getText().trim();
    if (fileName.length() == 0) {
        fileName = previouslyBrowsedArchive;
    }
    if (fileName.length() == 0) {
        // dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getLocation().toOSString());
        dialog.setFilterPath(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
    } else {
        File path = new File(fileName);
        if (path.exists()) {
            dialog.setFilterPath(new Path(fileName).toOSString());
        }
    }
    String selectedArchive = dialog.open();
    if (selectedArchive != null) {
        previouslyBrowsedArchive = selectedArchive;
        archivePathField.setText(previouslyBrowsedArchive);
        lastPath = archivePathField.getText().trim();
        saveExportPath(ARCHIVE_PATH, lastPath);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 42 with FileDialog

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

the class IconSelectionController method createCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createCommand()
     */
public Command createCommand(Button button) {
    Object data = button.getData(NAME);
    if (data != null) {
        if (ICON_SELECTION.equals(data)) {
            FileDialog dial = new FileDialog(composite.getShell(), SWT.NONE);
            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            dial.setFilterExtensions(new String[] { "*.jpg", "*.png", "*.gif" });
            String propertyName = (String) button.getData(PARAMETER_NAME);
            String file = dial.open();
            if (file != null) {
                if (!file.equals("")) {
                    //$NON-NLS-1$
                    if (!elem.getPropertyValue(propertyName).equals(file)) {
                        ImageData imageData = new ImageData(file);
                        if (ImageUtils.checkSize(ImageDescriptor.createFromImageData(imageData), ImageUtils.ICON_SIZE.ICON_32)) {
                            if (elem instanceof IProcess2) {
                                refreshIcon(imageData);
                                return new IconSelectionCommand((IProcess2) elem, ImageDescriptor.createFromImageData(imageData), file);
                            }
                        } else {
                            MessageDialog.openError(composite.getShell(), //$NON-NLS-1$ 
                            Messages.getString("IconSelectionController.MessageTitle"), //$NON-NLS-1$ 
                            Messages.getString("IconSelectionController.Messages"));
                        }
                    }
                }
            }
        } else if (ICON_REVERT.equals(data)) {
            if (elem instanceof IProcess2) {
                Image defaultIcon = RepositoryLabelProvider.getDefaultJobletImage(((IProcess2) elem).getProperty().getItem());
                ImageDescriptor imageData = ImageDescriptor.createFromImage(defaultIcon);
                refreshIcon(defaultIcon.getImageData());
                return new IconSelectionCommand((IProcess2) elem, imageData, null);
            }
        }
    }
    return null;
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) IProcess2(org.talend.core.model.process.IProcess2) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 43 with FileDialog

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

the class FileController method createCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createCommand()
     */
public Command createCommand(Button button) {
    FileDialog dial = new FileDialog(composite.getShell(), SWT.NONE);
    String propertyName = (String) button.getData(PARAMETER_NAME);
    Text filePathText = (Text) hashCurControls.get(propertyName);
    String extractedFilePath = PathExtractor.extractPath(filePathText.getText());
    dial.setFileName(new Path(extractedFilePath).toOSString());
    String file = dial.open();
    if (file != null) {
        if (!file.equals("")) {
            //$NON-NLS-1$
            if (!file.equals(elem.getPropertyValue(propertyName))) {
                String portableValue = Path.fromOSString(file).toPortableString();
                if (!isInWizard()) {
                    portableValue = TalendTextUtils.addQuotes(portableValue);
                }
                filePathText.setText(portableValue);
                return new PropertyChangeCommand(elem, propertyName, portableValue);
            }
        }
    }
    return null;
}
Also used : Path(org.eclipse.core.runtime.Path) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Text(org.eclipse.swt.widgets.Text) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 44 with FileDialog

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

the class RuntimeGraphcsComposite method createReportField.

/*  private void createInfoField(Composite parent) {

        infoComposite = createFlatFormComposite(parent, new FormToolkit(Display.getDefault()));
        FormLayout reportLayout = new FormLayout();
        reportLayout.marginWidth = 0;
        reportLayout.marginHeight = 0;
        infoComposite.setLayout(reportLayout);
        FormData reportData = new FormData();
        reportData.left = new FormAttachment(65, 5);
        reportData.right = new FormAttachment(100, -5);
        reportData.top = new FormAttachment(50, 0);
        reportData.bottom = new FormAttachment(100, -5);
        infoComposite.setLayoutData(reportData);

        Group group = new Group(infoComposite, SWT.NULL);
        FormLayout groupLayout = new FormLayout();
        groupLayout.marginWidth = 0;
        groupLayout.marginHeight = 0;
        group.setLayout(groupLayout);
        FormData groupData = new FormData();
        groupData.left = new FormAttachment(0, 0);
        groupData.right = new FormAttachment(100, 0);
        groupData.top = new FormAttachment(0, 0);
        groupData.bottom = new FormAttachment(100, 0);
        group.setLayoutData(groupData);
        group.setText("Run job Informations");

        infoField = new Text(group, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
        infoField.setEditable(false);
        infoField.setBackground(group.getBackground());

        FormData data;
        data = new FormData();
        data.left = new FormAttachment(0, 0);
        data.right = new FormAttachment(100, 0);
        data.top = new FormAttachment(0, 0);
        data.bottom = new FormAttachment(100, 0);
        infoField.setLayoutData(data);
    }*/
private void createReportField(Composite parent) {
    reportComposite = createFlatFormComposite(parent, new FormToolkit(Display.getDefault()));
    FormLayout reportLayout = new FormLayout();
    reportComposite.setLayout(reportLayout);
    FormData reportData = new FormData();
    reportData.left = new FormAttachment(65, 5);
    reportData.right = new FormAttachment(100, -5);
    reportData.top = new FormAttachment(0, 0);
    reportData.bottom = new FormAttachment(100, -5);
    reportComposite.setLayoutData(reportData);
    Group group = new Group(reportComposite, SWT.NULL);
    FormLayout groupLayout = new FormLayout();
    group.setLayout(groupLayout);
    FormData groupData = new FormData();
    groupData.left = new FormAttachment(0, 0);
    groupData.right = new FormAttachment(100, 0);
    groupData.top = new FormAttachment(0, 0);
    groupData.bottom = new FormAttachment(100, 0);
    group.setLayoutData(groupData);
    //$NON-NLS-1$
    group.setText("Job execution information");
    reportField = new StyledText(group, SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
    //may be CoreUIPlugin.setCSSClass can do this globally ,check later
    reportField.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
    FormData data;
    data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(93, 0);
    reportField.setLayoutData(data);
    displayReportField();
    //export button
    Button exportButton = new Button(group, SWT.PUSH);
    //$NON-NLS-1$
    exportButton.setText("Export");
    FormData exportData = new FormData();
    exportData.left = new FormAttachment(100, -70);
    exportData.right = new FormAttachment(100, 0);
    exportData.bottom = new FormAttachment(100, -1);
    exportButton.setLayoutData(exportData);
    exportButton.setEnabled(true);
    exportButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (messageManager == null || messageManager.getMessages().size() < 1) {
                //$NON-NLS-1$ //$NON-NLS-2$
                MessageDialog.openWarning(getShell(), "Warning", "No log to export.");
                return;
            }
            UnboundedFifoBuffer messages = messageManager.getMessages();
            Iterator iterator = messages.iterator();
            StringBuilder content = new StringBuilder();
            while (iterator.hasNext()) {
                ReportMessage message = (ReportMessage) iterator.next();
                content.append(message.getContent());
            }
            if (isMonitoring) {
                //$NON-NLS-1$ //$NON-NLS-2$
                MessageDialog.openWarning(getShell(), "Warning", "Waiting for job done.");
                return;
            }
            FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
            //$NON-NLS-1$
            dialog.setFilterPath(".");
            String fileName = dialog.open();
            if (fileName != null) {
                FileWriter writer = null;
                try {
                    writer = new FileWriter(fileName);
                    writer.write(content.toString());
                } catch (IOException e1) {
                    e1.printStackTrace();
                } finally {
                    try {
                        if (writer != null) {
                            writer.close();
                        }
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }
    });
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) IMonitoredMXBeanGroup(org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanGroup) Group(org.eclipse.swt.widgets.Group) StyledText(org.eclipse.swt.custom.StyledText) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FileWriter(java.io.FileWriter) ReportMessage(org.talend.designer.runtime.visualization.ReportMessage) IOException(java.io.IOException) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) UnboundedFifoBuffer(org.apache.commons.collections.buffer.UnboundedFifoBuffer) FileDialog(org.eclipse.swt.widgets.FileDialog) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 45 with FileDialog

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

the class ProjectSettingsPreferenceDialog method importPressed.

private void importPressed() {
    FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);
    //$NON-NLS-1$
    String[] files = new String[] { "*.xml" };
    fileDialog.setFilterExtensions(files);
    String path = fileDialog.open();
    ImportProjectSettings settings = new ImportProjectSettings(path);
    boolean error = false;
    ExportProjectSettings original = new ExportProjectSettings(TEMP_PRODUCT_SETTING_XML);
    original.saveProjectSettings();
    try {
        settings.updateProjectSettings();
    } catch (Exception e) {
        error = true;
        showErrorMessage();
    }
    // close the projec settings and open it again to get new settings
    if (!error) {
        close();
        ProjectSettingDialog dialog = new ProjectSettingDialog();
        dialog.open();
    }
}
Also used : ImportProjectSettings(org.talend.repository.ui.actions.ImportProjectSettings) ExportProjectSettings(org.talend.repository.ui.actions.ExportProjectSettings) FileDialog(org.eclipse.swt.widgets.FileDialog) PersistenceException(org.talend.commons.exception.PersistenceException)

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