Search in sources :

Example 6 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider 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 7 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project erlide_eclipse by erlang.

the class DirectorySelectUtil method chooseLocation.

public static IContainer chooseLocation(final String dialogTitle, final String labelText, final IProject project2, final String outputLocation, final Shell shell) {
    final IWorkspaceRoot root = project2.getWorkspace().getRoot();
    final Class<?>[] acceptedClasses = new Class[] { IProject.class, IFolder.class };
    final IProject[] allProjects = root.getProjects();
    final List<IProject> rejectedElements = new ArrayList<>(allProjects.length);
    for (IProject allProject : allProjects) {
        if (!allProject.equals(project2)) {
            rejectedElements.add(allProject);
        }
    }
    final ViewerFilter filter = new TypedViewerFilter(acceptedClasses, rejectedElements.toArray());
    final ILabelProvider lp = new WorkbenchLabelProvider();
    final ITreeContentProvider cp = new WorkbenchContentProvider();
    IResource initSelection = null;
    if (outputLocation != null) {
        initSelection = root.findMember(outputLocation);
    }
    final FolderSelectionDialog dialog = new FolderSelectionDialog(shell, lp, cp);
    dialog.setTitle(dialogTitle);
    final ISelectionStatusValidator validator = new ISelectionStatusValidator() {

        ISelectionStatusValidator myValidator = new TypedElementSelectionValidator(acceptedClasses, false);

        @Override
        public IStatus validate(final Object[] selection) {
            final IStatus typedStatus = myValidator.validate(selection);
            if (!typedStatus.isOK()) {
                return typedStatus;
            }
            if (selection[0] instanceof IFolder) {
                // }
                return new StatusInfo();
            }
            return new StatusInfo(IStatus.ERROR, "");
        }
    };
    dialog.setValidator(validator);
    dialog.setMessage(labelText);
    dialog.addFilter(filter);
    dialog.setInput(root);
    dialog.setInitialSelection(initSelection);
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    if (dialog.open() == Window.OK) {
        return (IContainer) dialog.getFirstResult();
    }
    return null;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IStatus(org.eclipse.core.runtime.IStatus) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TypedViewerFilter(org.erlide.ui.util.TypedViewerFilter) ArrayList(java.util.ArrayList) FolderSelectionDialog(org.erlide.ui.util.FolderSelectionDialog) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) TypedElementSelectionValidator(org.erlide.ui.util.TypedElementSelectionValidator) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) StatusInfo(org.erlide.ui.util.StatusInfo) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder) TypedViewerFilter(org.erlide.ui.util.TypedViewerFilter)

Example 8 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project liferay-ide by liferay.

the class NewCustomJSPsHookWizardPage method handleFileBrowseButton.

protected void handleFileBrowseButton(Text text) {
    ISelectionStatusValidator validator = getContainerDialogSelectionValidator();
    ViewerFilter filter = getContainerDialogViewerFilter();
    ITreeContentProvider contentProvider = new WorkbenchContentProvider();
    IDecoratorManager decoratorManager = PlatformUI.getWorkbench().getDecoratorManager();
    ILabelProvider labelProvider = new DecoratingLabelProvider(new WorkbenchLabelProvider(), decoratorManager.getLabelDecorator());
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), labelProvider, contentProvider);
    dialog.setValidator(validator);
    dialog.setTitle(J2EEUIMessages.CONTAINER_SELECTION_DIALOG_TITLE);
    dialog.setMessage(J2EEUIMessages.CONTAINER_SELECTION_DIALOG_DESC);
    dialog.addFilter(filter);
    dialog.setInput(CoreUtil.getWorkspaceRoot());
    if (dialog.open() == Window.OK) {
        Object element = dialog.getFirstResult();
        try {
            if (element instanceof IFolder) {
                IFolder folder = (IFolder) element;
                IProject project = CoreUtil.getProject(getDataModel().getStringProperty(PROJECT_NAME));
                IWebProject webproject = LiferayCore.create(IWebProject.class, project);
                if (webproject != null) {
                    IFolder defaultWebappRootFolder = webproject.getDefaultDocrootFolder();
                    if (folder.equals(defaultWebappRootFolder)) {
                        folder = folder.getFolder("custom_jsps");
                    }
                    String defaultWebappRootFolderFullPath = defaultWebappRootFolder.getFullPath().toPortableString();
                    String folderFullPath = folder.getFullPath().toPortableString();
                    int index = folderFullPath.indexOf(defaultWebappRootFolderFullPath);
                    if (index != -1) {
                        folderFullPath = folderFullPath.substring(index + defaultWebappRootFolderFullPath.length());
                    }
                    text.setText(folderFullPath);
                }
            }
        } catch (Exception ex) {
        // Do nothing
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IWebProject(com.liferay.ide.core.IWebProject) IDecoratorManager(org.eclipse.ui.IDecoratorManager) DecoratingLabelProvider(org.eclipse.jface.viewers.DecoratingLabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) IProject(org.eclipse.core.resources.IProject) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IFolder(org.eclipse.core.resources.IFolder)

Example 9 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project liferay-ide by liferay.

the class NewLanguagePropertiesHookWizardPage method handleFileBrowseButton.

protected void handleFileBrowseButton(Text text) {
    ISelectionStatusValidator validator = getContainerDialogSelectionValidator();
    ViewerFilter filter = getContainerDialogViewerFilter();
    ITreeContentProvider contentProvider = new WorkbenchContentProvider();
    IDecoratorManager decoratorManager = PlatformUI.getWorkbench().getDecoratorManager();
    ILabelProvider labelProvider = new DecoratingLabelProvider(new WorkbenchLabelProvider(), decoratorManager.getLabelDecorator());
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), labelProvider, contentProvider);
    dialog.setValidator(validator);
    dialog.setTitle(J2EEUIMessages.CONTAINER_SELECTION_DIALOG_TITLE);
    dialog.setMessage(J2EEUIMessages.CONTAINER_SELECTION_DIALOG_DESC);
    dialog.addFilter(filter);
    dialog.setInput(CoreUtil.getWorkspaceRoot());
    if (dialog.open() == Window.OK) {
        Object element = dialog.getFirstResult();
        try {
            if (element instanceof IFolder) {
                IFolder folder = (IFolder) element;
                IProject project = CoreUtil.getProject(getDataModel().getStringProperty(PROJECT_NAME));
                List<IFolder> sources = CoreUtil.getSourceFolders(JavaCore.create(project));
                if (ListUtil.isNotEmpty(sources) && folder.equals(sources.get(0))) {
                    folder = folder.getFolder("content");
                }
                text.setText(folder.getFullPath().toPortableString());
            }
        } catch (Exception ex) {
        // Do nothing
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IDecoratorManager(org.eclipse.ui.IDecoratorManager) DecoratingLabelProvider(org.eclipse.jface.viewers.DecoratingLabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) IProject(org.eclipse.core.resources.IProject) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IFolder(org.eclipse.core.resources.IFolder)

Example 10 with WorkbenchContentProvider

use of org.eclipse.ui.model.WorkbenchContentProvider in project liferay-ide by liferay.

the class NewPortalPropertiesHookWizardPage method handleBrowseButton.

protected void handleBrowseButton(Text text) {
    ISelectionStatusValidator validator = getContainerDialogSelectionValidator();
    ViewerFilter filter = getContainerDialogViewerFilter();
    ITreeContentProvider contentProvider = new WorkbenchContentProvider();
    IDecoratorManager decoratorManager = PlatformUI.getWorkbench().getDecoratorManager();
    ILabelProvider labelProvider = new DecoratingLabelProvider(new WorkbenchLabelProvider(), decoratorManager.getLabelDecorator());
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), labelProvider, contentProvider);
    dialog.setValidator(validator);
    dialog.setTitle(Msgs.portalPropertiesFile);
    dialog.setMessage(Msgs.portalPropertiesFile);
    dialog.addFilter(filter);
    dialog.setInput(CoreUtil.getWorkspaceRoot());
    if (dialog.open() == Window.OK) {
        Object element = dialog.getFirstResult();
        try {
            if (element instanceof IFile) {
                IFile file = (IFile) element;
                text.setText(file.getFullPath().toPortableString());
            } else if (element instanceof IFolder) {
                IFolder folder = (IFolder) element;
                IPath portalPropertiesPath = folder.getFullPath().append("portal.properties");
                text.setText(portalPropertiesPath.toPortableString());
            }
        } catch (Exception ex) {
        // Do nothing
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IPath(org.eclipse.core.runtime.IPath) IDecoratorManager(org.eclipse.ui.IDecoratorManager) DecoratingLabelProvider(org.eclipse.jface.viewers.DecoratingLabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)53 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)42 ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)32 IResource (org.eclipse.core.resources.IResource)27 IFile (org.eclipse.core.resources.IFile)18 ResourceComparator (org.eclipse.ui.views.navigator.ResourceComparator)18 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)16 IContainer (org.eclipse.core.resources.IContainer)15 IPath (org.eclipse.core.runtime.IPath)14 ArrayList (java.util.ArrayList)12 IStatus (org.eclipse.core.runtime.IStatus)12 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)12 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)11 ISelectionStatusValidator (org.eclipse.ui.dialogs.ISelectionStatusValidator)11 CoreException (org.eclipse.core.runtime.CoreException)10 Status (org.eclipse.core.runtime.Status)10 Composite (org.eclipse.swt.widgets.Composite)10 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)9 GridData (org.eclipse.swt.layout.GridData)9 Button (org.eclipse.swt.widgets.Button)9