Search in sources :

Example 71 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project cubrid-manager by CUBRID.

the class ImportExportConnectionDialog method okPressed.

protected void okPressed() {
    ActionExecutor executor = null;
    if (export) {
        FileDialog dialog = new FileDialog(getParentShell(), (export) ? SWT.SAVE : SWT.OPEN);
        dialog.setText(com.cubrid.cubridquery.ui.connection.Messages.exportConnectionsSelectPathMsg);
        dialog.setFilterExtensions(new String[] { "*.xml" });
        dialog.setFileName("export_connections");
        String fileName = dialog.open();
        if (fileName == null) {
            return;
        }
        executor = new ExportAction(fileName);
    } else {
        executor = new ImportAction();
    }
    if (executor.execute() == SUCCESS_CODE) {
        String msg = export ? com.cubrid.cubridquery.ui.connection.Messages.exportConnectionsSuccessMsg : com.cubrid.cubridquery.ui.connection.Messages.importConnectionsSuccessMsg;
        CommonUITool.openInformationBox(com.cubrid.common.ui.common.Messages.titleSuccess, msg);
        super.okPressed();
    }
}
Also used : ActionExecutor(com.cubrid.cubridquery.ui.connection.action.ActionExecutor) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 72 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project eclipse.platform.text by eclipse.

the class TemplatePreferencePage method import_.

private void import_() {
    FileDialog dialog = new FileDialog(getShell());
    dialog.setText(TemplatesMessages.TemplatePreferencePage_import_title);
    dialog.setFilterExtensions(new String[] { TemplatesMessages.TemplatePreferencePage_import_extension });
    String path = dialog.open();
    if (path == null)
        return;
    try {
        ArrayList<TemplatePersistenceData> selection = new ArrayList<>();
        TemplateReaderWriter reader = new TemplateReaderWriter();
        File file = new File(path);
        if (file.exists()) {
            try (InputStream input = new BufferedInputStream(new FileInputStream(file))) {
                TemplatePersistenceData[] datas = reader.read(input, null);
                for (int i = 0; i < datas.length; i++) {
                    TemplatePersistenceData data = datas[i];
                    fTemplateStore.add(data);
                    String id = data.getId();
                    if (id == null) {
                        selection.add(data);
                    } else {
                        data = fTemplateStore.getTemplateData(id);
                        if (data != null) {
                            selection.add(data);
                        }
                    }
                }
            }
        }
        fTableViewer.refresh();
        fTableViewer.setAllChecked(false);
        fTableViewer.setCheckedElements(getEnabledTemplates());
        fTableViewer.setSelection(new StructuredSelection(selection), true);
        selectionChanged1();
    } catch (FileNotFoundException e) {
        openReadErrorDialog(e);
    } catch (IOException e) {
        openReadErrorDialog(e);
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FileNotFoundException(java.io.FileNotFoundException) TemplateReaderWriter(org.eclipse.jface.text.templates.persistence.TemplateReaderWriter) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 73 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project linuxtools by eclipse.

the class SaveChartAction method askForAndPrepareFile.

/**
 * Ask the user for the path to save the file at, and check if this path overwrites any existing file.
 * (Note that using dialog.setOverwrite(true) is insufficient, as the path name may be appended with a
 * file extension after the standard overwrite checks occur.)
 * @return A file with the specified pathname, appended with an appropriate extension.
 */
private File askForAndPrepareFile() {
    final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    final FileDialog dialog = new FileDialog(shell, SWT.SAVE);
    dialog.setFilterExtensions(EXTENSIONS);
    dialog.setText(Messages.ChartConstants_SAVE_CHART_DIALOG_TEXT);
    dialog.setFileName(title);
    do {
        String path = dialog.open();
        if (path == null) {
            // Cancelled
            return null;
        }
        path = makePathWithVerifiedExt(path);
        File file = new File(path);
        if (shouldOverwrite(file, shell)) {
            return file;
        }
        // If not overwriting, bring up dialog again (loop)
        dialog.setFileName(file.getName());
    } while (true);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 74 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project linuxtools by eclipse.

the class PerfOptionsTab method showFileDialog.

// Displays a file dialog to allow the user to select the kernel image file
private void showFileDialog(Shell shell) {
    FileDialog fDialog = new FileDialog(shell, SWT.OPEN);
    File kernel = new File(txtKernelLocation.getText());
    if (!kernel.exists()) {
        // $NON-NLS-1$
        kernel = new File("/boot");
        if (!kernel.exists()) {
            // $NON-NLS-1$
            kernel = new File("/");
        }
    }
    fDialog.setFileName(kernel.toString());
    fDialog.setText(Messages.PerfOptionsTab_Kernel_Prompt);
    String newKernel = fDialog.open();
    if (newKernel != null) {
        kernel = new File(newKernel);
        if (!kernel.exists()) {
            MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.RETRY | SWT.CANCEL);
            mb.setMessage(Messages.PerfOptionsTab_File_DNE);
            switch(mb.open()) {
                case SWT.RETRY:
                    showFileDialog(shell);
                    break;
                default:
            }
        } else {
            txtKernelLocation.setText(newKernel);
        }
    }
}
Also used : FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 75 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project linuxtools by eclipse.

the class STCSourceNotFoundEditor method locateFile.

private void locateFile() {
    FileDialog dialog = new FileDialog(getEditorSite().getShell(), SWT.NONE);
    IPath missingPath = getMissingFile();
    dialog.setFilterNames(new String[] { Messages.STCSourceNotFoundEditor_missing_source_file });
    // $NON-NLS-1$
    dialog.setFilterExtensions(new String[] { "*." + missingPath.getFileExtension() });
    String res = dialog.open();
    if (res != null) {
        Path newPath = new Path(res);
        if (newPath.lastSegment().equalsIgnoreCase(missingPath.lastSegment())) {
            if (missingPath.segmentCount() > 1) {
                int missingPathSegCount = missingPath.segmentCount() - 2;
                int newPathSegCount = newPath.segmentCount() - 2;
                while (missingPathSegCount >= 0 && newPathSegCount >= 0) {
                    if (!newPath.segment(newPathSegCount).equalsIgnoreCase(missingPath.segment(missingPathSegCount))) {
                        break;
                    }
                    newPathSegCount--;
                    missingPathSegCount--;
                }
                IPath compPath = missingPath.removeLastSegments(missingPath.segmentCount() - missingPathSegCount - 1);
                IPath newSourcePath = newPath.removeLastSegments(newPath.segmentCount() - newPathSegCount - 1);
                try {
                    addSourceMappingToCommon(compPath, newSourcePath);
                } catch (CoreException e) {
                }
            }
            openSourceFileAtLocation(getProject(), newPath, getLineNumber());
            closeEditor();
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) FileDialog(org.eclipse.swt.widgets.FileDialog)

Aggregations

FileDialog (org.eclipse.swt.widgets.FileDialog)512 File (java.io.File)198 SelectionEvent (org.eclipse.swt.events.SelectionEvent)181 Button (org.eclipse.swt.widgets.Button)181 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)160 Label (org.eclipse.swt.widgets.Label)153 Text (org.eclipse.swt.widgets.Text)151 Composite (org.eclipse.swt.widgets.Composite)136 Shell (org.eclipse.swt.widgets.Shell)120 GridData (org.eclipse.swt.layout.GridData)110 ModifyListener (org.eclipse.swt.events.ModifyListener)109 ModifyEvent (org.eclipse.swt.events.ModifyEvent)107 GridLayout (org.eclipse.swt.layout.GridLayout)105 Group (org.eclipse.swt.widgets.Group)90 Event (org.eclipse.swt.widgets.Event)76 Listener (org.eclipse.swt.widgets.Listener)76 Display (org.eclipse.swt.widgets.Display)72 FormAttachment (org.eclipse.swt.layout.FormAttachment)68 FormData (org.eclipse.swt.layout.FormData)68 FormLayout (org.eclipse.swt.layout.FormLayout)68