Search in sources :

Example 26 with Dialog

use of org.eclipse.jface.dialogs.Dialog in project webtools.sourceediting by eclipse.

the class CleanupdocumentHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    ITextEditor textEditor = null;
    if (editor instanceof ITextEditor)
        textEditor = (ITextEditor) editor;
    else {
        Object o = editor.getAdapter(ITextEditor.class);
        if (o != null)
            textEditor = (ITextEditor) o;
    }
    if (textEditor != null) {
        final ITextEditor finalTextEditor = textEditor;
        Dialog cleanupDialog = new CleanupDialogXML(editor.getSite().getShell());
        if (cleanupDialog.open() == Window.OK) {
            // setup runnable
            Runnable runnable = new Runnable() {

                public void run() {
                    IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
                    if (cleanupProcessor != null) {
                        IStructuredModel model = null;
                        try {
                            model = StructuredModelManager.getModelManager().getExistingModelForEdit(finalTextEditor.getDocumentProvider().getDocument(finalTextEditor.getEditorInput()));
                            if (model != null) {
                                cleanupProcessor.cleanupModel(model);
                            }
                        } finally {
                            if (model != null) {
                                model.releaseFromEdit();
                            }
                        }
                    }
                }
            };
            // TODO: make independent of 'model'.
            IStructuredModel model = null;
            try {
                model = StructuredModelManager.getModelManager().getExistingModelForEdit(textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()));
                if (model != null) {
                    // begin recording
                    ITextSelection selection = (ITextSelection) textEditor.getSelectionProvider().getSelection();
                    model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_, SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength());
                    // tell the model that we are about to make a big
                    // model change
                    model.aboutToChangeModel();
                    // run
                    BusyIndicator.showWhile(textEditor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(), runnable);
                }
            } finally {
                if (model != null) {
                    // tell the model that we are done with the big
                    // model
                    // change
                    model.changedModel();
                    // end recording
                    ITextSelection selection = (ITextSelection) textEditor.getSelectionProvider().getSelection();
                    model.endRecording(this, selection.getOffset(), selection.getLength());
                    model.releaseFromEdit();
                }
            }
        }
    }
    return null;
}
Also used : IStructuredCleanupProcessor(org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupProcessor) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Dialog(org.eclipse.jface.dialogs.Dialog) CleanupDialogXML(org.eclipse.wst.xml.ui.internal.actions.CleanupDialogXML) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 27 with Dialog

use of org.eclipse.jface.dialogs.Dialog in project webtools.sourceediting by eclipse.

the class CleanupActionXMLDelegate method run.

public void run(IAction action) {
    if (fEditor instanceof ITextEditor) {
        final ITextEditor editor = (ITextEditor) fEditor;
        Dialog cleanupDialog = new CleanupDialogXML(editor.getSite().getShell());
        if (cleanupDialog.open() == Window.OK) {
            // setup runnable
            Runnable runnable = new Runnable() {

                public void run() {
                    IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
                    if (cleanupProcessor != null) {
                        IStructuredModel model = null;
                        try {
                            model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
                            if (model != null) {
                                cleanupProcessor.cleanupModel(model);
                            }
                        } finally {
                            if (model != null) {
                                model.releaseFromEdit();
                            }
                        }
                    }
                }
            };
            // TODO: make independent of 'model'.
            IStructuredModel model = null;
            try {
                model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
                if (model != null) {
                    // begin recording
                    ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
                    model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_, SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength());
                    // tell the model that we are about to make a big
                    // model change
                    model.aboutToChangeModel();
                    // run
                    BusyIndicator.showWhile(fEditor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(), runnable);
                }
            } finally {
                if (model != null) {
                    // tell the model that we are done with the big
                    // model
                    // change
                    model.changedModel();
                    // end recording
                    ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
                    model.endRecording(this, selection.getOffset(), selection.getLength());
                    model.releaseFromEdit();
                }
            }
        }
    }
}
Also used : IStructuredCleanupProcessor(org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupProcessor) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Dialog(org.eclipse.jface.dialogs.Dialog) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 28 with Dialog

use of org.eclipse.jface.dialogs.Dialog in project azure-tools-for-java by Microsoft.

the class ServicePrincipalLoginDialog method createDialogArea.

/**
 * Create contents of the dialog.
 *
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    GridLayout gridLayout = (GridLayout) container.getLayout();
    gridLayout.marginRight = 10;
    gridLayout.marginLeft = 10;
    gridLayout.numColumns = 2;
    Label lblNewLabel = new Label(container, SWT.NONE);
    lblNewLabel.setText("Tenant Id: ");
    txtTenantId = new Text(container, SWT.BORDER);
    txtTenantId.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label lblClientId = new Label(container, SWT.NONE);
    lblClientId.setText("Client Id: ");
    txtClientId = new Text(container, SWT.BORDER);
    txtClientId.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label lblSecret = new Label(container, SWT.NONE);
    lblSecret.setText("Secret: ");
    Group composite = new Group(container, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    GridLayout glComposite = new GridLayout(2, false);
    glComposite.marginTop = 1;
    glComposite.marginRight = 10;
    glComposite.marginLeft = 10;
    glComposite.marginWidth = 0;
    composite.setLayout(glComposite);
    radioPassword = new Button(composite, SWT.RADIO);
    radioPassword.setSelection(true);
    radioPassword.setText("Password:");
    txtPassword = new Text(composite, SWT.BORDER | SWT.PASSWORD);
    txtPassword.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    radioCertificate = new Button(composite, SWT.RADIO);
    radioCertificate.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    radioCertificate.setText("Certificate:");
    Composite compositeCert = new Composite(composite, SWT.NONE);
    compositeCert.setLayout(new FormLayout());
    GridData gdCompositeCert = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gdCompositeCert.widthHint = 191;
    compositeCert.setLayoutData(gdCompositeCert);
    txtCertificate = new Text(compositeCert, SWT.BORDER | SWT.READ_ONLY);
    FormData fdTxtCertificate = new FormData();
    fdTxtCertificate.top = new FormAttachment(0, 3);
    fdTxtCertificate.left = new FormAttachment(0, 0);
    txtCertificate.setLayoutData(fdTxtCertificate);
    Button btnOpenFileButton = new Button(compositeCert, SWT.CENTER);
    fdTxtCertificate.right = new FormAttachment(btnOpenFileButton, -6);
    FormData fdBtnOpenFileButton = new FormData();
    fdBtnOpenFileButton.top = new FormAttachment(0, 1);
    fdBtnOpenFileButton.right = new FormAttachment(100);
    btnOpenFileButton.setLayoutData(fdBtnOpenFileButton);
    btnOpenFileButton.setText("...");
    btnOpenFileButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            FileDialog dlg = new FileDialog(btnOpenFileButton.getShell(), SWT.OPEN);
            dlg.setText("Open");
            String path = dlg.open();
            if (path == null)
                return;
            txtCertificate.setText(path);
        }
    });
    btnOpenFileButton.setEnabled(false);
    Label lblJson = new Label(container, SWT.NONE);
    lblJson.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true, 1, 1));
    lblJson.setText("JSON:");
    Composite composite2 = new Composite(container, SWT.NONE);
    composite2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    composite2.setLayout(new FillLayout(SWT.HORIZONTAL));
    txtJson = new Text(composite2, SWT.MULTI | SWT.BORDER);
    txtJson.setLayoutData(new GridData(GridData.FILL_BOTH));
    txtJson.addModifyListener(event -> {
        this.updateFromJsonEditor.debounce();
    });
    radioCertificate.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            btnOpenFileButton.setEnabled(true);
        }
    });
    radioPassword.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            btnOpenFileButton.setEnabled(false);
        }
    });
    Stream.of(txtCertificate, txtClientId, txtPassword, txtTenantId).forEach(d -> d.addModifyListener(r -> updateToJsonEditor.debounce()));
    Stream.of(radioCertificate, radioPassword).forEach(d -> d.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            updateToJsonEditor.debounce();
        }
    }));
    return container;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Arrays(java.util.Arrays) JsonUtils(com.microsoft.azuretools.utils.JsonUtils) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) StringUtils(org.apache.commons.lang3.StringUtils) Point(org.eclipse.swt.graphics.Point) LinkedHashMap(java.util.LinkedHashMap) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) JsonSyntaxException(com.google.gson.JsonSyntaxException) FormLayout(org.eclipse.swt.layout.FormLayout) FileDialog(org.eclipse.swt.widgets.FileDialog) FormData(org.eclipse.swt.layout.FormData) Debouncer(com.microsoft.azure.toolkit.lib.common.utils.Debouncer) FormAttachment(org.eclipse.swt.layout.FormAttachment) TailingDebouncer(com.microsoft.azure.toolkit.lib.common.utils.TailingDebouncer) AuthConfiguration(com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration) Group(org.eclipse.swt.widgets.Group) Stream(java.util.stream.Stream) Dialog(org.eclipse.jface.dialogs.Dialog) SWT(org.eclipse.swt.SWT) AuthType(com.microsoft.azure.toolkit.lib.auth.model.AuthType) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Pattern(java.util.regex.Pattern) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FillLayout(org.eclipse.swt.layout.FillLayout) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileDialog(org.eclipse.swt.widgets.FileDialog) FormAttachment(org.eclipse.swt.layout.FormAttachment) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 29 with Dialog

use of org.eclipse.jface.dialogs.Dialog in project azure-tools-for-java by Microsoft.

the class AzureDialogProtertiesHelper method addOKTelemetryProperties.

default void addOKTelemetryProperties(final Map<String, String> properties) {
    if (!(this instanceof Dialog))
        return;
    Control[] controls = ((Dialog) this).getShell().getChildren();
    java.util.List<Control> controlsList = new ArrayList<Control>();
    for (Control control : controls) {
        controlsList = getAllControls(control);
        for (Control c : controlsList) {
            if (c instanceof Button) {
                Button button = (Button) c;
                String btnInfoString = button.getText();
                if (btnInfoString == null || btnInfoString.trim().isEmpty()) {
                    btnInfoString = button.getLocation() == null ? "" : String.valueOf(button.getLocation());
                }
                if ((c.getStyle() & SWT.CHECK) != 0) {
                    properties.put("JCheckBox." + btnInfoString + ".Selected", String.valueOf(button.getSelection()));
                } else if ((c.getStyle() & SWT.RADIO) != 0) {
                    properties.put("JRadioButton." + btnInfoString + ".Selected", String.valueOf(button.getSelection()));
                }
            }
            if (c instanceof Combo) {
                Combo combo = (Combo) c;
                String comboInfoString = combo.getLocation() == null ? "" : String.valueOf(combo.getLocation());
                int idx = combo.getSelectionIndex();
                String comboItemString = null;
                try {
                    comboItemString = combo.getItem(idx);
                } catch (Exception ex) {
                    comboItemString = "";
                }
                properties.put("JComboBox." + comboInfoString + ".Selected", comboItemString);
            }
        }
    }
    return;
}
Also used : Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) Dialog(org.eclipse.jface.dialogs.Dialog) ArrayList(java.util.ArrayList) Combo(org.eclipse.swt.widgets.Combo)

Example 30 with Dialog

use of org.eclipse.jface.dialogs.Dialog in project tesb-studio-se by Talend.

the class RouteResourcesButtonPart method buttonSelected.

@Override
protected void buttonSelected(SelectionEvent e) {
    try {
        Class<?> dialogClass = Platform.getBundle("org.talend.camel.designer").loadClass("org.talend.camel.designer.dialog.RouteResourceSelectionDialog");
        Dialog dialog = (Dialog) dialogClass.getConstructor(Shell.class).newInstance(getShell());
        if (dialog.open() == Dialog.OK) {
            RepositoryNode resourceNode = (RepositoryNode) dialogClass.getMethod("getResult").invoke(dialog);
            if (resourceNode != null) {
                listener.routeResourceNodeSelected(resourceNode);
            }
        }
    } catch (Exception e1) {
        ExceptionHandler.process(new IllegalStateException("Can't load RouteResourceSelectionDialog from specific bundle", e1));
    }
}
Also used : Dialog(org.eclipse.jface.dialogs.Dialog) RepositoryNode(org.talend.repository.model.RepositoryNode)

Aggregations

Dialog (org.eclipse.jface.dialogs.Dialog)49 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)15 FileDialog (org.eclipse.swt.widgets.FileDialog)11 Composite (org.eclipse.swt.widgets.Composite)9 ArrayList (java.util.ArrayList)8 WizardDialog (org.eclipse.jface.wizard.WizardDialog)8 Control (org.eclipse.swt.widgets.Control)7 Shell (org.eclipse.swt.widgets.Shell)7 GridData (org.eclipse.swt.layout.GridData)6 Button (org.eclipse.swt.widgets.Button)6 ITextSelection (org.eclipse.jface.text.ITextSelection)5 GridLayout (org.eclipse.swt.layout.GridLayout)5 IStructuredCleanupProcessor (org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupProcessor)5 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)5 File (java.io.File)4 Client (name.abuchen.portfolio.model.Client)4 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)4 List (java.util.List)3 SWT (org.eclipse.swt.SWT)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3