Fixed: [ Issue 40 ] Add support for import resolution across multiple folders https://code.google.com/p/protobuf-dt/issues/detail?id=40 Cleaning up UI code.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGenerationEditor.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGenerationEditor.java index 49709ef..f4bd419 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGenerationEditor.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGenerationEditor.java
@@ -10,6 +10,7 @@ import static com.google.eclipse.protobuf.ui.preferences.compiler.Messages.*; import static java.util.Collections.unmodifiableList; +import static org.eclipse.jface.window.Window.OK; import java.util.*; import java.util.List; @@ -109,7 +110,7 @@ int selectionIndex = tblCodeGenerationOptions.getSelectionIndex(); CodeGeneration option = options.get(selectionIndex); EditCodeGenerationDialog dialog = new EditCodeGenerationDialog(getShell(), option); - if (dialog.open()) { + if (dialog.open() == OK) { tblVwrCodeGenerationOptions.refresh(); if (dataChangedListener != null) dataChangedListener.dataChanged(); }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/EditCodeGenerationDialog.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/EditCodeGenerationDialog.java index 32d6c98..8b56731 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/EditCodeGenerationDialog.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/EditCodeGenerationDialog.java
@@ -9,36 +9,32 @@ package com.google.eclipse.protobuf.ui.preferences.compiler; import static com.google.eclipse.protobuf.ui.preferences.compiler.Messages.*; -import static com.google.eclipse.protobuf.ui.swt.Shells.centerShell; import static org.eclipse.core.resources.IResource.FOLDER; -import static org.eclipse.core.runtime.IStatus.OK; +import static org.eclipse.jface.dialogs.IDialogConstants.OK_ID; +import static org.eclipse.swt.layout.GridData.*; import static org.eclipse.xtext.util.Strings.isEmpty; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.IStatus; import org.eclipse.swt.SWT; import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.*; +import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.*; +import com.google.eclipse.protobuf.ui.preferences.InputDialog; + /** * Dialog where users can edit a single code generation option. * * @author alruiz@google.com (Alex Ruiz) */ -public class EditCodeGenerationDialog extends Dialog { +public class EditCodeGenerationDialog extends InputDialog { - private final Shell parent; private final CodeGeneration option; - private boolean result; - private Shell shell; - private Text txtOutputDirectory; private Button btnEnabled; - private Text lblError; - private Button btnOk; - private Button btnCancel; + private Text txtError; /** * Creates a new </code>{@link EditCodeGenerationDialog}</code>. @@ -46,80 +42,40 @@ * @param option the code generation option to edit. */ public EditCodeGenerationDialog(Shell parent, CodeGeneration option) { - super(parent, SWT.NONE); - this.parent = parent; + super(parent, editCodeGenerationOptionTitle + option.language().name()); this.option = option; - getStyle(); - setText(editCodeGenerationOptionTitle + option.language().name()); - } - /** - * Opens this dialog. - * @return {@code true} if the user made a selection and pressed "OK" or {@code false} if the user pressed "Cancel." - */ - public boolean open() { - result = false; - shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE); - shell.setText(getText()); - createAndCenterContent(); - shell.open(); - Display display = parent.getDisplay(); - while (!shell.isDisposed()) - if (!display.readAndDispatch()) display.sleep(); - return result; } - private void createAndCenterContent() { - shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE); - shell.setSize(564, 158); - shell.setText(getText()); - shell.setLayout(new GridLayout(2, false)); + /** {@inheritDoc} */ + @Override protected Control createDialogArea(Composite parent) { + Composite cmpDialogArea = (Composite) super.createDialogArea(parent); - btnEnabled = new Button(shell, SWT.CHECK); + btnEnabled = new Button(cmpDialogArea, SWT.CHECK); btnEnabled.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1)); btnEnabled.setText(enabled); btnEnabled.setSelection(option.isEnabled()); - Label lblOutputDirectoryName = new Label(shell, SWT.NONE); + Label lblOutputDirectoryName = new Label(cmpDialogArea, SWT.NONE); lblOutputDirectoryName.setText(outputDirectoryPrompt); - txtOutputDirectory = new Text(shell, SWT.BORDER); + txtOutputDirectory = new Text(cmpDialogArea, SWT.BORDER); txtOutputDirectory.setEnabled(option.isEnabled()); + GridData gd_txtOutputDirectory = new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1); gd_txtOutputDirectory.widthHint = 200; txtOutputDirectory.setLayoutData(gd_txtOutputDirectory); txtOutputDirectory.setText(option.outputDirectory()); - lblError = new Text(shell, SWT.READ_ONLY | SWT.WRAP); - GridData gd_lblError = new GridData(GridData.GRAB_HORIZONTAL - | GridData.HORIZONTAL_ALIGN_FILL); + txtError = new Text(cmpDialogArea, SWT.READ_ONLY | SWT.WRAP); + GridData gd_lblError = new GridData(GRAB_HORIZONTAL | HORIZONTAL_ALIGN_FILL); gd_lblError.horizontalSpan = 2; - lblError.setLayoutData(gd_lblError); - lblError.setBackground(lblError.getDisplay() - .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); -// -// lblError = new Label(shell, SWT.NONE); -// lblError.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); - - Composite composite = new Composite(shell, SWT.NONE); - composite.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, true, true, 2, 1)); - composite.setLayout(new GridLayout(2, true)); - - btnOk = new Button(composite, SWT.NONE); - btnOk.setEnabled(false); - btnOk.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); - btnOk.setBounds(0, 0, 92, 29); - btnOk.setText(ok); - - btnCancel = new Button(composite, SWT.NONE); - btnCancel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); - btnCancel.setText(cancel); + txtError.setLayoutData(gd_lblError); + txtError.setBackground(txtError.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); addEventListeners(); - shell.setDefaultButton(btnOk); - shell.pack(); - - centerWindow(); + applyDialogFont(cmpDialogArea); + return cmpDialogArea; } private void addEventListeners() { @@ -129,19 +85,6 @@ checkState(); } }); - btnOk.addSelectionListener(new SelectionAdapter() { - @Override public void widgetSelected(SelectionEvent e) { - option.enabled(btnEnabled.getSelection()); - option.outputDirectory(enteredOuptutDirectory()); - result = true; - shell.dispose(); - } - }); - btnCancel.addSelectionListener(new SelectionAdapter() { - @Override public void widgetSelected(SelectionEvent e) { - shell.dispose(); - } - }); txtOutputDirectory.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { checkState(); @@ -171,13 +114,20 @@ } private void pageIsNowInvalid(String errorMessage) { - lblError.setText(errorMessage); - btnOk.setEnabled(false); + txtError.setText(errorMessage); + getButton(OK_ID).setEnabled(false); } private void pageIsNowValid() { - lblError.setText(""); - btnOk.setEnabled(true); + txtError.setText(""); + getButton(OK_ID).setEnabled(true); + } + + /** {@inheritDoc} */ + @Override protected void okPressed() { + option.enabled(btnEnabled.getSelection()); + option.outputDirectory(enteredOuptutDirectory()); + super.okPressed(); } private boolean outputDirectoryEntered() { @@ -187,8 +137,4 @@ private String enteredOuptutDirectory() { return txtOutputDirectory.getText().trim(); } - - private void centerWindow() { - centerShell(shell, parent); - } }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/AddDirectoryDialog.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/AddDirectoryDialog.java index d88b0f8..2d6d412 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/AddDirectoryDialog.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/AddDirectoryDialog.java
@@ -9,7 +9,7 @@ package com.google.eclipse.protobuf.ui.preferences.paths; import static com.google.eclipse.protobuf.ui.preferences.paths.Messages.*; -import static com.google.eclipse.protobuf.ui.preferences.paths.SelectDirectoryDialogs.*; +import static com.google.eclipse.protobuf.ui.preferences.paths.DirectorySelectionDialogs.*; import static org.eclipse.jface.dialogs.IDialogConstants.OK_ID; import static org.eclipse.xtext.util.Strings.isEmpty;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/SelectDirectoryDialogs.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectorySelectionDialogs.java similarity index 97% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/SelectDirectoryDialogs.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectorySelectionDialogs.java index 3912eeb..02460b7 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/SelectDirectoryDialogs.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectorySelectionDialogs.java
@@ -27,7 +27,7 @@ * * @author alruiz@google.com (Alex Ruiz) */ -class SelectDirectoryDialogs { +class DirectorySelectionDialogs { private static final String PLUGIN_ID = "com.google.eclipse.protobuf.ui"; @@ -74,5 +74,5 @@ return ResourcesPlugin.getWorkspace().getRoot(); } - private SelectDirectoryDialogs() {} + private DirectorySelectionDialogs() {} }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/swt/Shells.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/swt/Shells.java deleted file mode 100644 index a3d1eaa..0000000 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/swt/Shells.java +++ /dev/null
@@ -1,29 +0,0 @@ -/* - * Copyright (c) 2011 Google Inc. - * - * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse - * Public License v1.0 which accompanies this distribution, and is available at - * - * http://www.eclipse.org/legal/epl-v10.html - */ -package com.google.eclipse.protobuf.ui.swt; - -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Shell; - -/** - * Utility methods related to <code>{@link Shell}</code>. - * - * @author alruiz@google.com (Alex Ruiz) - */ -public class Shells { - - public static void centerShell(Shell target, Shell parent) { - Rectangle parentRect = parent.getBounds(); - Rectangle targetRect = target.getBounds(); - int x = parentRect.x + (parentRect.width - targetRect.width) / 2; - int y = parentRect.y + (parentRect.height - targetRect.height) / 2; - target.setBounds(x, y, targetRect.width, targetRect.height); - } - -}