Search in sources :

Example 81 with FileDialog

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

the class CovManager method openTraceFileStream.

// transform String path to stream
private DataInput openTraceFileStream(String filePath, String extension, Map<File, File> sourcePath) throws FileNotFoundException {
    Path p = new Path(filePath);
    // get the file path transformed to work on local OS (e.g. Windows)
    filePath = getTransformedPathString(p);
    File f = new File(filePath).getAbsoluteFile();
    String filename = f.getName();
    if (f.isFile() && f.canRead()) {
        FileInputStream fis = new FileInputStream(f);
        InputStream inputStream = new BufferedInputStream(fis);
        return new DataInputStream(inputStream);
    } else {
        // $NON-NLS-1$
        String postfix = "";
        File dir = null;
        do {
            if (postfix.isEmpty()) {
                postfix = f.getName();
            } else {
                postfix = f.getName() + File.separator + postfix;
            }
            f = f.getParentFile();
            if (f != null) {
                dir = sourcePath.get(f);
            } else {
                break;
            }
        } while (dir == null);
        if (dir != null) {
            f = new File(dir, postfix);
            if (f.isFile() && f.canRead()) {
                return openTraceFileStream(f.getAbsolutePath(), extension, sourcePath);
            }
        }
        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        FileDialog fg = new FileDialog(shell, SWT.OPEN);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        fg.setFilterExtensions(new String[] { "*" + extension, "*.*", "*" });
        fg.setFileName(filename);
        fg.setText(NLS.bind(Messages.CovManager_No_FilePath_Error, new Object[] { filePath, filename }));
        String s = fg.open();
        if (s == null) {
            return null;
        } else {
            f = new File(s).getAbsoluteFile();
            addSourceLookup(sourcePath, f, new File(filePath).getAbsoluteFile());
            if (f.isFile() && f.canRead()) {
                FileInputStream fis = new FileInputStream(f);
                InputStream inputStream = new BufferedInputStream(fis);
                return new DataInputStream(inputStream);
            }
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Shell(org.eclipse.swt.widgets.Shell) BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IBinaryObject(org.eclipse.cdt.core.IBinaryParser.IBinaryObject) DataInputStream(java.io.DataInputStream) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) FileInputStream(java.io.FileInputStream)

Example 82 with FileDialog

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

the class LaunchWizard method promptForInputs.

private void promptForInputs() {
    InputDialog id = new // $NON-NLS-1$
    InputDialog(// $NON-NLS-1$
    new Shell(), // $NON-NLS-1$
    Messages.getString("LaunchWizard.WelcomeWizard"), // $NON-NLS-1$
    Messages.getString("LaunchWizard.Text1") + // $NON-NLS-1$
    Messages.getString("LaunchWizard.Text2") + // $NON-NLS-1$
    Messages.getString("LaunchWizard.Text3"), getLaunchManager().generateLaunchConfigurationName(Messages.getString("LaunchWizard.NamePrefix")), // $NON-NLS-1$
    null);
    id.open();
    if (id.getReturnCode() == Window.CANCEL) {
        return;
    }
    name = id.getValue();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();
    IPath location = root.getLocation();
    workspacePath = location.toString();
    sh = new Shell();
    sh.setSize(WIDTH, HEIGHT);
    sh.setLayout(new GridLayout(1, false));
    sh.setText(name);
    // $NON-NLS-1$
    Image img = new Image(sh.getDisplay(), PluginConstants.getPluginLocation() + "systemtapbanner.png");
    Composite imageCmp = new Composite(sh, SWT.BORDER);
    imageCmp.setLayout(new FillLayout());
    GridData imageData = new GridData(650, 157);
    imageData.horizontalAlignment = SWT.CENTER;
    imageCmp.setLayoutData(imageData);
    imageCmp.setBackgroundImage(img);
    Composite fileComp = new Composite(sh, SWT.NONE);
    fileComp.setLayout(new GridLayout(2, false));
    fileComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    GridDataFactory labelData = GridDataFactory.fillDefaults().grab(true, false).span(2, 1);
    Label scriptLabel = new Label(fileComp, SWT.HORIZONTAL);
    // $NON-NLS-1$
    scriptLabel.setText(Messages.getString("LaunchWizard.Script"));
    labelData.applyTo(scriptLabel);
    GridDataFactory textData = GridDataFactory.fillDefaults().grab(true, false).hint(WIDTH, SWT.DEFAULT);
    scriptLocation = new Text(fileComp, SWT.SINGLE | SWT.BORDER);
    textData.applyTo(scriptLocation);
    Button scriptButton = new Button(fileComp, SWT.PUSH);
    // $NON-NLS-1$
    scriptButton.setText(Messages.getString("SystemTapOptionsTab.BrowseFiles"));
    scriptButton.setLayoutData(new GridData());
    scriptButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        String filePath = scriptLocation.getText();
        FileDialog dialog = new FileDialog(sh, SWT.SAVE);
        filePath = dialog.open();
        if (filePath != null) {
            scriptLocation.setText(filePath);
        }
    }));
    GridData gd2 = new GridData();
    gd2.horizontalSpan = 3;
    Label binaryLabel = new Label(fileComp, SWT.HORIZONTAL);
    // $NON-NLS-1$
    binaryLabel.setText(Messages.getString("LaunchWizard.BinFile"));
    labelData.applyTo(binaryLabel);
    binaryLocation = new Text(fileComp, SWT.SINGLE | SWT.BORDER);
    textData.applyTo(binaryLocation);
    Button binaryButton = new Button(fileComp, SWT.PUSH);
    // $NON-NLS-1$
    binaryButton.setText(Messages.getString("SystemTapOptionsTab.WorkspaceButton2"));
    binaryButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(sh, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
        // $NON-NLS-1$
        dialog.setTitle(Messages.getString("SystemTapOptionsTab.SelectResource"));
        // $NON-NLS-1$
        dialog.setMessage(Messages.getString("SystemTapOptionsTab.SelectSuppressions"));
        dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
        dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
        if (dialog.open() == IDialogConstants.OK_ID) {
            IResource resource = (IResource) dialog.getFirstResult();
            String arg = resource.getFullPath().toString();
            binaryLocation.setText(workspacePath + arg);
        }
    }));
    Composite argumentsComp = new Composite(sh, SWT.BORDER_DASH);
    argumentsComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    argumentsComp.setLayout(new GridLayout(2, false));
    Label argumentsLabel = new Label(argumentsComp, SWT.HORIZONTAL);
    // $NON-NLS-1$
    argumentsLabel.setText(Messages.getString("LaunchWizard.Args"));
    labelData.applyTo(argumentsLabel);
    argumentsLocation = new Text(argumentsComp, SWT.MULTI | SWT.WRAP | SWT.BORDER);
    GridData gd3 = new GridData(GridData.FILL_HORIZONTAL);
    gd3.heightHint = 200;
    argumentsLocation.setLayoutData(gd3);
    Button argumentsButton = new Button(argumentsComp, SWT.PUSH);
    // $NON-NLS-1$
    argumentsButton.setText(Messages.getString("LaunchWizard.Func"));
    argumentsButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> argumentsLocation.setText(// $NON-NLS-1$
    argumentsLocation.getText() + " process(\"" + binaryLocation.getText() + // $NON-NLS-1$
    "\").function(\"\")")));
    // TODO: Don't use blank labels to move button to the right column :P
    Label blankLabel2 = new Label(argumentsComp, SWT.HORIZONTAL);
    // $NON-NLS-1$
    blankLabel2.setText("");
    Button launch = new Button(sh, SWT.PUSH);
    launch.setLayoutData(new GridData(GridData.CENTER, GridData.BEGINNING, false, false));
    // $NON-NLS-1$
    launch.setText(Messages.getString("LaunchWizard.Launch"));
    launch.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        scriptPath = scriptLocation.getText();
        binaryPath = binaryLocation.getText();
        arguments = argumentsLocation.getText();
        ILaunchConfigurationWorkingCopy wc = createConfiguration(null, name);
        try {
            // $NON-NLS-1$
            finishLaunch(scriptPath + ": " + binName, mode, wc);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        sh.dispose();
    }));
    // TODO: Verify that this works
    Display.getCurrent().asyncExec(() -> sh.open());
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Image(org.eclipse.swt.graphics.Image) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IPath(org.eclipse.core.runtime.IPath) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) IEditorPart(org.eclipse.ui.IEditorPart) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) FileDialog(org.eclipse.swt.widgets.FileDialog) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) Display(org.eclipse.swt.widgets.Display) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Window(org.eclipse.jface.window.Window) IResource(org.eclipse.core.resources.IResource) SWT(org.eclipse.swt.SWT) ISelection(org.eclipse.jface.viewers.ISelection) Label(org.eclipse.swt.widgets.Label) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) PluginConstants(org.eclipse.linuxtools.internal.callgraph.core.PluginConstants) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) InputDialog(org.eclipse.jface.dialogs.InputDialog) IPath(org.eclipse.core.runtime.IPath) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FillLayout(org.eclipse.swt.layout.FillLayout) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Image(org.eclipse.swt.graphics.Image) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) Button(org.eclipse.swt.widgets.Button) IWorkspace(org.eclipse.core.resources.IWorkspace) GridData(org.eclipse.swt.layout.GridData) FileDialog(org.eclipse.swt.widgets.FileDialog) IResource(org.eclipse.core.resources.IResource)

Example 83 with FileDialog

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

the class CallgraphView method writeToDot.

private void writeToDot(boolean mode, Set<Integer> keySet) {
    Shell sh = new Shell();
    FileDialog dialog = new FileDialog(sh, SWT.SAVE);
    String filePath = dialog.open();
    if (filePath != null) {
        File f = new File(filePath);
        f.delete();
        try {
            f.createNewFile();
        } catch (IOException e) {
            return;
        }
        try (BufferedWriter out = new BufferedWriter(new FileWriter(f))) {
            // $NON-NLS-1$
            StringBuilder build = new StringBuilder("");
            // $NON-NLS-1$
            out.write("digraph stapgraph {\n");
            for (int i : keySet) {
                if (i == 0) {
                    continue;
                }
                StapData d = g.getNodeData(i);
                if ((d.isCollapsed != mode) && !d.isOnlyChildWithThisName()) {
                    continue;
                }
                // $NON-NLS-1$ //$NON-NLS-2$
                build.append(i + " [label=\"" + d.name + " ");
                // $NON-NLS-1$
                build.append(StapNode.numberFormat.format((float) d.getTime() / g.getTotalTime() * 100) + "%\"]\n");
                int j = d.parent;
                if (mode) {
                    j = d.collapsedParent;
                }
                if (!keySet.contains(j) || j == 0) {
                    continue;
                }
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                String called = mode ? " [label=\"" + g.getNodeData(i).timesCalled + "\"]\n" : "\n";
                // $NON-NLS-1$
                build.append(j + "->" + i);
                build.append(called);
                out.write(build.toString());
                build.setLength(0);
            }
            // $NON-NLS-1$
            out.write("}");
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) FileWriter(java.io.FileWriter) IOException(java.io.IOException) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 84 with FileDialog

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

the class SRPMImportPage method createSourceRPMCombo.

private void createSourceRPMCombo(Composite parent) {
    Group specGrid = new Group(parent, SWT.NONE);
    specGrid.setLayout(new GridLayout());
    // $NON-NLS-1$
    specGrid.setText(Messages.getString("SRPMImportPage.SRPM_Name"));
    specGrid.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
    Composite sourceSpecComposite = new Composite(specGrid, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    sourceSpecComposite.setLayout(layout);
    sourceSpecComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
    sourceSRPM = new Text(sourceSpecComposite, SWT.BORDER);
    sourceSRPM.setToolTipText(Messages.getString(// $NON-NLS-1$
    "SRPMImportPage.toolTip_SRPM_Name"));
    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    sourceSRPM.setLayoutData(gridData);
    sourceSRPM.addModifyListener(e -> {
        boolean validSRPM = canFinish();
        if (validSRPM) {
            setPageComplete(validSRPM);
            changeProjectSettings();
        }
    });
    Button srpmBrowse = new Button(sourceSpecComposite, SWT.PUSH);
    srpmBrowse.setToolTipText(Messages.getString(// $NON-NLS-1$
    "SRPMImportPage.toolTip_Open_file_navigator"));
    // $NON-NLS-1$
    srpmBrowse.setText(Messages.getString("RPMPage.Browse"));
    srpmBrowse.addListener(SWT.Selection, event -> {
        FileDialog srpmBrowseDialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
        String selectedSRPMName = srpmBrowseDialog.open();
        if (selectedSRPMName != null) {
            File testSRPMfilename = new File(selectedSRPMName);
            if (testSRPMfilename.isFile()) {
                sourceSRPM.setText(selectedSRPMName);
            }
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) Text(org.eclipse.swt.widgets.Text) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 85 with FileDialog

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

the class OpenFileHandler method queryFile.

/**
 * Request the name and location of the file to the user.
 * @return the File object associated to the selected file.
 */
protected File queryFile() {
    FileDialog dialog = new FileDialog(window.getShell(), dialogStyle());
    // $NON-NLS-1$
    dialog.setFilterExtensions(new String[] { "*.stp" });
    dialog.setText(dialogName());
    String path = dialog.open();
    if (path != null && path.length() > 0) {
        cancelled = false;
        return new File(path);
    }
    cancelled = true;
    return null;
}
Also used : FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

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