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;
}
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();
}
}
}
}
}
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;
}
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;
}
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));
}
}
Aggregations