Search in sources :

Example 66 with FileDialog

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

the class DialogTab method createButtonSelected.

/**
 * Handle the create button selection event.
 *
 * @param event org.eclipse.swt.events.SelectionEvent
 */
void createButtonSelected(SelectionEvent event) {
    /* Compute the appropriate dialog style */
    int style = getDefaultStyle();
    if (okButton.getEnabled() && okButton.getSelection())
        style |= SWT.OK;
    if (cancelButton.getEnabled() && cancelButton.getSelection())
        style |= SWT.CANCEL;
    if (yesButton.getEnabled() && yesButton.getSelection())
        style |= SWT.YES;
    if (noButton.getEnabled() && noButton.getSelection())
        style |= SWT.NO;
    if (retryButton.getEnabled() && retryButton.getSelection())
        style |= SWT.RETRY;
    if (abortButton.getEnabled() && abortButton.getSelection())
        style |= SWT.ABORT;
    if (ignoreButton.getEnabled() && ignoreButton.getSelection())
        style |= SWT.IGNORE;
    if (iconErrorButton.getEnabled() && iconErrorButton.getSelection())
        style |= SWT.ICON_ERROR;
    if (iconInformationButton.getEnabled() && iconInformationButton.getSelection())
        style |= SWT.ICON_INFORMATION;
    if (iconQuestionButton.getEnabled() && iconQuestionButton.getSelection())
        style |= SWT.ICON_QUESTION;
    if (iconWarningButton.getEnabled() && iconWarningButton.getSelection())
        style |= SWT.ICON_WARNING;
    if (iconWorkingButton.getEnabled() && iconWorkingButton.getSelection())
        style |= SWT.ICON_WORKING;
    if (primaryModalButton.getEnabled() && primaryModalButton.getSelection())
        style |= SWT.PRIMARY_MODAL;
    if (applicationModalButton.getEnabled() && applicationModalButton.getSelection())
        style |= SWT.APPLICATION_MODAL;
    if (systemModalButton.getEnabled() && systemModalButton.getSelection())
        style |= SWT.SYSTEM_MODAL;
    if (sheetButton.getSelection())
        style |= SWT.SHEET;
    if (saveButton.getEnabled() && saveButton.getSelection())
        style |= SWT.SAVE;
    if (openButton.getEnabled() && openButton.getSelection())
        style |= SWT.OPEN;
    if (multiButton.getEnabled() && multiButton.getSelection())
        style |= SWT.MULTI;
    /* Open the appropriate dialog type */
    String name = dialogCombo.getText();
    if (name.equals(ControlExample.getResourceString("ColorDialog"))) {
        ColorDialog dialog = new ColorDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setRGB(colorDialogResult);
            dialog.setRGBs(colorDialogCustomColors);
        }
        dialog.setText(ControlExample.getResourceString("Title"));
        RGB result = dialog.open();
        textWidget.append(ControlExample.getResourceString("ColorDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        textWidget.append("getRGB() = " + dialog.getRGB() + Text.DELIMITER);
        textWidget.append("getRGBs() =" + Text.DELIMITER);
        RGB[] rgbs = dialog.getRGBs();
        if (rgbs != null) {
            for (RGB rgbColor : rgbs) {
                textWidget.append("\t" + rgbColor + Text.DELIMITER);
            }
        }
        textWidget.append(Text.DELIMITER);
        colorDialogResult = result;
        colorDialogCustomColors = rgbs;
        return;
    }
    if (name.equals(ControlExample.getResourceString("DirectoryDialog"))) {
        DirectoryDialog dialog = new DirectoryDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setFilterPath(directoryDialogResult);
        }
        dialog.setMessage(ControlExample.getResourceString("Example_string"));
        dialog.setText(ControlExample.getResourceString("Title"));
        String result = dialog.open();
        textWidget.append(ControlExample.getResourceString("DirectoryDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER + Text.DELIMITER);
        directoryDialogResult = result;
        return;
    }
    if (name.equals(ControlExample.getResourceString("FileDialog"))) {
        FileDialog dialog = new FileDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setFileName(fileDialogResult);
            dialog.setFilterIndex(fileDialogIndexResult);
        }
        dialog.setFilterNames(FilterNames);
        dialog.setFilterExtensions(FilterExtensions);
        dialog.setText(ControlExample.getResourceString("Title"));
        String result = dialog.open();
        textWidget.append(ControlExample.getResourceString("FileDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        textWidget.append("getFilterIndex() =" + dialog.getFilterIndex() + Text.DELIMITER);
        textWidget.append("getFilterPath() =" + dialog.getFilterPath() + Text.DELIMITER);
        textWidget.append("getFileName() =" + dialog.getFileName() + Text.DELIMITER);
        textWidget.append("getFileNames() =" + Text.DELIMITER);
        String[] files = dialog.getFileNames();
        for (String file : files) {
            textWidget.append("\t" + file + Text.DELIMITER);
        }
        textWidget.append(Text.DELIMITER);
        fileDialogResult = result;
        fileDialogIndexResult = dialog.getFilterIndex();
        return;
    }
    if (name.equals(ControlExample.getResourceString("FontDialog"))) {
        FontDialog dialog = new FontDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setFontList(fontDialogFontListResult);
            dialog.setRGB(fontDialogColorResult);
        }
        dialog.setEffectsVisible(effectsVisibleButton.getSelection());
        dialog.setText(ControlExample.getResourceString("Title"));
        FontData result = dialog.open();
        textWidget.append(ControlExample.getResourceString("FontDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        textWidget.append("getFontList() =" + Text.DELIMITER);
        FontData[] fonts = dialog.getFontList();
        if (fonts != null) {
            for (FontData font : fonts) {
                textWidget.append("\t" + font + Text.DELIMITER);
            }
        }
        textWidget.append("getEffectsVisible() = " + dialog.getEffectsVisible() + Text.DELIMITER);
        textWidget.append("getRGB() = " + dialog.getRGB() + Text.DELIMITER + Text.DELIMITER);
        fontDialogFontListResult = dialog.getFontList();
        fontDialogColorResult = dialog.getRGB();
        return;
    }
    if (name.equals(ControlExample.getResourceString("PrintDialog"))) {
        PrintDialog dialog = new PrintDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setPrinterData(printDialogResult);
        }
        dialog.setText(ControlExample.getResourceString("Title"));
        PrinterData result = dialog.open();
        textWidget.append(ControlExample.getResourceString("PrintDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        if (result != null) {
            textWidget.append("printerData.scope = " + (result.scope == PrinterData.PAGE_RANGE ? "PAGE_RANGE" : result.scope == PrinterData.SELECTION ? "SELECTION" : "ALL_PAGES") + Text.DELIMITER);
            textWidget.append("printerData.startPage = " + result.startPage + Text.DELIMITER);
            textWidget.append("printerData.endPage = " + result.endPage + Text.DELIMITER);
            textWidget.append("printerData.printToFile = " + result.printToFile + Text.DELIMITER);
            textWidget.append("printerData.fileName = " + result.fileName + Text.DELIMITER);
            textWidget.append("printerData.orientation = " + (result.orientation == PrinterData.LANDSCAPE ? "LANDSCAPE" : "PORTRAIT") + Text.DELIMITER);
            textWidget.append("printerData.copyCount = " + result.copyCount + Text.DELIMITER);
            textWidget.append("printerData.collate = " + result.collate + Text.DELIMITER);
            textWidget.append("printerData.duplex = " + (result.duplex == PrinterData.DUPLEX_LONG_EDGE ? "DUPLEX_LONG_EDGE" : result.duplex == PrinterData.DUPLEX_SHORT_EDGE ? "DUPLEX_SHORT_EDGE" : "NONE") + Text.DELIMITER);
        }
        textWidget.append(Text.DELIMITER);
        printDialogResult = result;
        return;
    }
    if (name.equals(ControlExample.getResourceString("MessageBox"))) {
        MessageBox dialog = new MessageBox(shell, style);
        dialog.setMessage(ControlExample.getResourceString("Example_string"));
        dialog.setText(ControlExample.getResourceString("Title"));
        int result = dialog.open();
        textWidget.append(ControlExample.getResourceString("MessageBox") + Text.DELIMITER);
        /*
			 * The resulting integer depends on the original
			 * dialog style.  Decode the result and display it.
			 */
        switch(result) {
            case SWT.OK:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.OK"));
                break;
            case SWT.YES:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.YES"));
                break;
            case SWT.NO:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.NO"));
                break;
            case SWT.CANCEL:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.CANCEL"));
                break;
            case SWT.ABORT:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.ABORT"));
                break;
            case SWT.RETRY:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.RETRY"));
                break;
            case SWT.IGNORE:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.IGNORE"));
                break;
            default:
                textWidget.append(ControlExample.getResourceString("Result", "" + result));
                break;
        }
        textWidget.append(Text.DELIMITER + Text.DELIMITER);
    }
}
Also used : FontDialog(org.eclipse.swt.widgets.FontDialog) PrintDialog(org.eclipse.swt.printing.PrintDialog) FontData(org.eclipse.swt.graphics.FontData) RGB(org.eclipse.swt.graphics.RGB) MessageBox(org.eclipse.swt.widgets.MessageBox) ColorDialog(org.eclipse.swt.widgets.ColorDialog) PrinterData(org.eclipse.swt.printing.PrinterData) FileDialog(org.eclipse.swt.widgets.FileDialog) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 67 with FileDialog

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

the class Test_org_eclipse_swt_widgets_FileDialog method test_ConstructorLorg_eclipse_swt_widgets_ShellI.

@Test
public void test_ConstructorLorg_eclipse_swt_widgets_ShellI() {
    // Test FileDialog(Shell, int)
    FileDialog fd;
    fd = new FileDialog(shell, SWT.NULL);
    int style = fd.getStyle();
    style &= ~SWT.LEFT_TO_RIGHT;
    style &= ~SWT.RIGHT_TO_LEFT;
    assertTrue(style == SWT.APPLICATION_MODAL);
    fd = new FileDialog(shell, SWT.APPLICATION_MODAL);
    style = fd.getStyle();
    style &= ~SWT.LEFT_TO_RIGHT;
    style &= ~SWT.RIGHT_TO_LEFT;
    assertTrue(style == SWT.APPLICATION_MODAL);
    fd = new FileDialog(shell, SWT.PRIMARY_MODAL);
    style = fd.getStyle();
    style &= ~SWT.LEFT_TO_RIGHT;
    style &= ~SWT.RIGHT_TO_LEFT;
    assertTrue(style == SWT.PRIMARY_MODAL);
    fd = new FileDialog(shell, SWT.SYSTEM_MODAL);
    style = fd.getStyle();
    style &= ~SWT.LEFT_TO_RIGHT;
    style &= ~SWT.RIGHT_TO_LEFT;
    assertTrue(style == SWT.SYSTEM_MODAL);
}
Also used : FileDialog(org.eclipse.swt.widgets.FileDialog) Test(org.junit.Test)

Example 68 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project pentaho-kettle by pentaho.

the class JobEntryJobDialog method pickFileVFS.

protected void pickFileVFS() {
    FileDialog dialog = new FileDialog(shell, SWT.OPEN);
    dialog.setFilterExtensions(Const.STRING_JOB_FILTER_EXT);
    dialog.setFilterNames(Const.getJobFilterNames());
    String prevName = jobMeta.environmentSubstitute(wPath.getText());
    String parentFolder = null;
    try {
        parentFolder = KettleVFS.getFilename(KettleVFS.getFileObject(jobMeta.environmentSubstitute(jobMeta.getFilename())).getParent());
    } catch (Exception e) {
    // not that important
    }
    if (!Utils.isEmpty(prevName)) {
        try {
            if (KettleVFS.fileExists(prevName)) {
                dialog.setFilterPath(KettleVFS.getFilename(KettleVFS.getFileObject(prevName).getParent()));
            } else {
                if (!prevName.endsWith(".kjb")) {
                    prevName = getEntryName(Const.trim(wPath.getText()) + ".kjb");
                }
                if (KettleVFS.fileExists(prevName)) {
                    wPath.setText(prevName);
                    specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
                    return;
                } else {
                    // File specified doesn't exist. Ask if we should create the file...
                    // 
                    MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
                    mb.setMessage(BaseMessages.getString(PKG, "JobJob.Dialog.CreateJobQuestion.Message"));
                    // Sorry!
                    mb.setText(BaseMessages.getString(PKG, "JobJob.Dialog.CreateJobQuestion.Title"));
                    int answer = mb.open();
                    if (answer == SWT.YES) {
                        Spoon spoon = Spoon.getInstance();
                        spoon.newJobFile();
                        JobMeta newJobMeta = spoon.getActiveJob();
                        newJobMeta.initializeVariablesFrom(jobEntry);
                        newJobMeta.setFilename(jobMeta.environmentSubstitute(prevName));
                        wPath.setText(prevName);
                        specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
                        spoon.saveFile();
                        return;
                    }
                }
            }
        } catch (Exception e) {
            dialog.setFilterPath(parentFolder);
        }
    } else if (!Utils.isEmpty(parentFolder)) {
        dialog.setFilterPath(parentFolder);
    }
    String fname = dialog.open();
    if (fname != null) {
        File file = new File(fname);
        String name = file.getName();
        String parentFolderSelection = file.getParentFile().toString();
        if (!Utils.isEmpty(parentFolder) && parentFolder.equals(parentFolderSelection)) {
            wPath.setText(getEntryName(name));
        } else {
            wPath.setText(fname);
        }
    }
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) Spoon(org.pentaho.di.ui.spoon.Spoon) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) KettleException(org.pentaho.di.core.exception.KettleException) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 69 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project archi by archimatetool.

the class ColoursFontsPreferencePage method exportUserColors.

/**
 * @throws IOException
 * Export a user color scheme
 */
private void exportUserColors() throws IOException {
    FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
    dialog.setText(Messages.ColoursFontsPreferencePage_5);
    // $NON-NLS-1$
    dialog.setFileName("ArchiColours.prefs");
    String path = dialog.open();
    if (path == null) {
        return;
    }
    // Make sure the file does not already exist
    File file = new File(path);
    if (file.exists()) {
        boolean result = MessageDialog.openQuestion(getShell(), Messages.ColoursFontsPreferencePage_15, NLS.bind(Messages.ColoursFontsPreferencePage_16, file));
        if (!result) {
            return;
        }
    }
    PreferenceStore store = new PreferenceStore(path);
    saveColors(store);
    store.save();
}
Also used : FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) PreferenceStore(org.eclipse.jface.preference.PreferenceStore)

Example 70 with FileDialog

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

the class ImportExportConnectionDialog method createDialogArea.

protected Control createDialogArea(Composite parent) {
    Composite parentComp = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(parentComp, SWT.NONE);
    composite.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    {
        GridLayout layout = new GridLayout();
        layout.numColumns = 3;
        layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
        layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
        layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
        layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
        composite.setLayout(layout);
    }
    if (!export) {
        lblFromFolder = new Label(composite, SWT.SHADOW_IN);
        lblFromFolder.setText(Messages.lblFromFile);
        lblFromFolder.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
        GridData fromData = CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1);
        fromData.horizontalIndent = 0;
        txFromFolder = new Text(composite, SWT.BORDER | SWT.LEFT | SWT.READ_ONLY);
        txFromFolder.setLayoutData(fromData);
        GridData browserData = CommonUITool.createGridData(1, 1, -1, -1);
        browserData.horizontalIndent = 10;
        browserData.widthHint = 80;
        btnBrowser = new Button(composite, SWT.CENTER);
        btnBrowser.setText(Messages.lblBrowser);
        btnBrowser.setLayoutData(browserData);
        btnBrowser.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                FileDialog dialog = new FileDialog(getParentShell(), (export) ? SWT.SAVE : SWT.OPEN);
                dialog.setFilterExtensions(new String[] { "*.xml" });
                String fileName = dialog.open();
                if (fileName != null) {
                    txFromFolder.setText(fileName);
                }
                if (!export) {
                    List<DatabaseUIWrapper> servers = parseFile(fileName);
                    hostListView.setInput(servers);
                    ImportExportConnectionDialog.this.getButton(IDialogConstants.OK_ID).setEnabled(hostListView.getCheckedElements().length > 0);
                }
            }
        });
    }
    setMessage((export) ? Messages.msgExportServer : Messages.msgImportServer);
    setTitle((export) ? Messages.tlExportServer : Messages.tlImportServer);
    getShell().setText((export) ? Messages.tlExportServer : Messages.tlImportServer);
    createTable(composite);
    return super.createDialogArea(parent);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text) List(java.util.List) ArrayList(java.util.ArrayList) 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