diff options
Diffstat (limited to 'src/plugins/common/src/com/motorola/studio/android/wizards')
8 files changed, 1234 insertions, 0 deletions
diff --git a/src/plugins/common/src/com/motorola/studio/android/wizards/BaseWizard.java b/src/plugins/common/src/com/motorola/studio/android/wizards/BaseWizard.java new file mode 100644 index 0000000..a9f9146 --- /dev/null +++ b/src/plugins/common/src/com/motorola/studio/android/wizards/BaseWizard.java @@ -0,0 +1,63 @@ +/*
+* Copyright (C) 2012 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package com.motorola.studio.android.wizards;
+
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.Wizard;
+
+/**
+ * Base class to simple wizards (without progress monitor and help).
+ */
+public abstract class BaseWizard extends Wizard
+{
+ public BaseWizard()
+ {
+ setNeedsProgressMonitor(true);
+ setHelpAvailable(false);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#performFinish()
+ */
+ @Override
+ public boolean performFinish()
+ {
+ return doPerformFinish();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#canFinish()
+ */
+ @Override
+ public boolean canFinish()
+ {
+ IWizardPage currentPage = getContainer().getCurrentPage();
+ if (getNextPage(currentPage) == null)
+ {
+ return currentPage.isPageComplete();
+ }
+ return super.canFinish();
+ }
+
+ /**
+ * This method is executed when the user finishes the wizard.
+ *
+ * @return <code>true</code> if the method succeed.
+ */
+ protected abstract boolean doPerformFinish();
+}
diff --git a/src/plugins/common/src/com/motorola/studio/android/wizards/BaseWizardPage.java b/src/plugins/common/src/com/motorola/studio/android/wizards/BaseWizardPage.java new file mode 100644 index 0000000..f47f863 --- /dev/null +++ b/src/plugins/common/src/com/motorola/studio/android/wizards/BaseWizardPage.java @@ -0,0 +1,176 @@ +/*
+* Copyright (C) 2012 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package com.motorola.studio.android.wizards;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.ui.PlatformUI;
+
+import com.motorola.studio.android.common.utilities.ui.WidgetsFactory;
+import com.motorola.studio.android.wizards.elements.IBaseBlock;
+
+/**
+ * Base class for the wizard pages.
+ */
+public abstract class BaseWizardPage extends WizardPage implements Listener
+{
+
+ /**
+ * Default wizard page Composite
+ */
+ private Composite composite;
+
+ /**
+ * Default wizard page GridLayout
+ */
+ private GridLayout layout;
+
+ /**
+ * The block used by this wizard page.
+ */
+ protected IBaseBlock block;
+
+ private String helpID = null;
+
+ /**
+ * Constructs a new instance using a given block.
+ *
+ * @param block Block used to render the screen.
+ * @param title Window title
+ * @param description Window description
+ */
+ public BaseWizardPage(IBaseBlock block, String title, String description)
+ {
+ this(block, title, description, null);
+ this.block = block;
+ }
+
+ /**
+ * Constructs a new instance using a given block.
+ *
+ * @param block Block used to render the screen.
+ * @param title Window title
+ * @param description Window description
+ * @param contextHelpID The context help id used to this page
+ */
+ public BaseWizardPage(IBaseBlock block, String title, String description, String contextHelpID)
+ {
+ super(title);
+ setTitle(title);
+ setDescription(description);
+ this.block = block;
+ helpID = contextHelpID;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
+ * .Composite)
+ */
+ public void createControl(Composite parent)
+ {
+ getComposite(parent).setLayout(getLayout());
+ if (this.block != null)
+ {
+ this.block.setShell(getShell());
+ Composite blockComposite = this.block.createContent(getComposite(parent));
+ if (helpID != null)
+ {
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(blockComposite, helpID);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(getComposite(parent), helpID);
+ }
+ }
+ setControl(getComposite(parent));
+ setErrorMessage(null);
+ getComposite(parent).addListener(SWT.Modify, this);
+ getComposite(parent).addListener(SWT.Selection, this);
+ }
+
+ /**
+ * Returns the default composite of this wizard page.
+ *
+ * @param parent The parent composite.
+ * @return The composite of this wizard page.
+ */
+ protected Composite getComposite(Composite parent)
+ {
+ if (this.composite == null)
+ {
+ this.composite = WidgetsFactory.createComposite(parent);
+ }
+ return this.composite;
+ }
+
+ /**
+ * Returns the default grid layout of this wizard page.
+ *
+ * @return The default grid layout of this wizard page.
+ */
+ protected GridLayout getLayout()
+ {
+ if (this.layout == null)
+ {
+ this.layout = WidgetsFactory.createGridLayout();
+ }
+ return this.layout;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.
+ * Event)
+ */
+ public void handleEvent(Event event)
+ {
+ String message = this.block.getErrorMessage();
+ setErrorMessage(message);
+ setPageComplete(message == null);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
+ */
+ @Override
+ public boolean isPageComplete()
+ {
+ if (this.block == null)
+ {
+ return true;
+ }
+ return this.block.isPageComplete();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.wizard.WizardPage#canFlipToNextPage()
+ */
+ @Override
+ public boolean canFlipToNextPage()
+ {
+ if (this.block == null)
+ {
+ return true;
+ }
+ return this.block.canFlipToNextPage() && (getNextPage() != null);
+ }
+}
diff --git a/src/plugins/common/src/com/motorola/studio/android/wizards/elements/AddInputRemoveButtons.java b/src/plugins/common/src/com/motorola/studio/android/wizards/elements/AddInputRemoveButtons.java new file mode 100644 index 0000000..99d8f92 --- /dev/null +++ b/src/plugins/common/src/com/motorola/studio/android/wizards/elements/AddInputRemoveButtons.java @@ -0,0 +1,115 @@ +/* +* Copyright (C) 2012 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.motorola.studio.android.wizards.elements; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; + +import com.motorola.studio.android.common.utilities.i18n.UtilitiesNLS; + +/** + * Add, Input and Remove buttons for wizards. + * + */ +public class AddInputRemoveButtons extends Composite +{ + + private Button addButton; + + private Button inputButton; + + private Button removeButton; + + /** + * Create Add, Input and Remove buttons for wizards. + * @param parent the composite parent + */ + public AddInputRemoveButtons(Composite parent) + { + super(parent, SWT.NONE); + createContents(); + } + + /** + * Create Contents + */ + private void createContents() + { + GridData gridData; + GridLayout gridLayout = new GridLayout(); + gridLayout.marginWidth = 0; + gridLayout.marginHeight = 0; + setLayout(gridLayout); + gridData = new GridData(); + gridData.verticalAlignment = GridData.BEGINNING; + + setLayoutData(gridData); + + createAddButton(); + + createInputButton(); + + createRemoveButton(); + } + + protected void createAddButton() + { + addButton = new Button(this, SWT.PUSH); + addButton.setText(UtilitiesNLS.UI_AddRemoveButtons_AddButtonLabel); + } + + private void createInputButton() + { + inputButton = new Button(this, SWT.PUSH); + inputButton.setText(UtilitiesNLS.AddInputRemoveButtons_InputButtonLabel); + } + + protected void createRemoveButton() + { + removeButton = new Button(this, SWT.PUSH); + removeButton.setText(UtilitiesNLS.UI_AddRemoveButtons_RemoveButtonLabel); + } + + /** + * Return the Add button instance. + * @return the Add button instance + */ + public Button getAddButton() + { + return addButton; + } + + /** + * Return the Input button instance. + * @return the Input button instance + */ + public Button getInputButton() + { + return inputButton; + } + + /** + * Return the Remove button instance. + * @return the Remove button instance + */ + public Button getRemoveButton() + { + return removeButton; + } +} diff --git a/src/plugins/common/src/com/motorola/studio/android/wizards/elements/AddRemoveButtons.java b/src/plugins/common/src/com/motorola/studio/android/wizards/elements/AddRemoveButtons.java new file mode 100644 index 0000000..9ce9381 --- /dev/null +++ b/src/plugins/common/src/com/motorola/studio/android/wizards/elements/AddRemoveButtons.java @@ -0,0 +1,97 @@ +/* +* Copyright (C) 2012 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.motorola.studio.android.wizards.elements; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import com.motorola.studio.android.common.utilities.i18n.UtilitiesNLS; + +/** + * Add and Remove Buttons for Wizards + */ +public class AddRemoveButtons extends Composite +{ + + private Button addButton; + + private Button removeButton; + + /** + * Create an Add and Remove Buttons for Wizards + * @param parent + */ + public AddRemoveButtons(Composite parent) + { + super(parent, SWT.NONE); + createContents(); + } + + /** + * Create Contents + */ + private void createContents() + { + GridData gridData; + GridLayout gridLayout = new GridLayout(); + gridLayout.marginWidth = 0; + gridLayout.marginHeight = 0; + setLayout(gridLayout); + gridData = new GridData(); + gridData.verticalAlignment = GridData.BEGINNING; + + setLayoutData(gridData); + addButton = new Button(this, SWT.PUSH); + addButton.setText(UtilitiesNLS.UI_AddRemoveButtons_AddButtonLabel); + + //Separator + Label separator = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL); + separator.setFont(getFont()); + separator.setVisible(false); + GridData gd = new GridData(); + gd.horizontalAlignment = GridData.FILL; + gd.verticalAlignment = GridData.BEGINNING; + gd.verticalIndent = 4; + separator.setLayoutData(gd); + // Separator + + removeButton = new Button(this, SWT.PUSH); + removeButton.setText(UtilitiesNLS.UI_AddRemoveButtons_RemoveButtonLabel); + } + + /** + * Return the Add button instance. + * @return + */ + public Button getAddButton() + { + return addButton; + } + + /** + * Return the Remove Button instance. + * @return + */ + public Button getRemoveButton() + { + return removeButton; + } + +} diff --git a/src/plugins/common/src/com/motorola/studio/android/wizards/elements/FileChooser.java b/src/plugins/common/src/com/motorola/studio/android/wizards/elements/FileChooser.java new file mode 100644 index 0000000..566c2b0 --- /dev/null +++ b/src/plugins/common/src/com/motorola/studio/android/wizards/elements/FileChooser.java @@ -0,0 +1,305 @@ +/* +* Copyright (C) 2012 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.motorola.studio.android.wizards.elements; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowData; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; +import org.eclipse.ui.dialogs.ISelectionStatusValidator; +import org.eclipse.ui.model.WorkbenchContentProvider; +import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.eclipse.ui.views.navigator.ResourceComparator; + +import com.motorola.studio.android.common.CommonPlugin; +import com.motorola.studio.android.common.utilities.i18n.UtilitiesNLS; + +/** + * Composite to allow users to choose between filesystem and workspace files + */ +public class FileChooser extends Composite +{ + /* + * Label: TextField + * Workspace... Filesystem... + * + */ + private final String label; + + private Label fileLabel = null; + + private Text pathWidget = null; + + private Button filesystem = null, workspace = null; + + private String[] extensionFilter = null; + + private IContainer container; + + /** + * Constructs a new FileChooser object + * @param parent the parent composite + * @param style the style + * @param label A label to put before the path text or null to no label + */ + public FileChooser(Composite parent, int style, String label) + { + super(parent, style); + this.label = label; + setupLayout(); + createFields(); + } + + /** + * Constructs a new FileChooser object + * + * @param container Container in which limits the range of the filter. For instance + * if a project is passed as a container, all the search will be done within the passed-project. + * @param parent the parent composite + * @param style the style + * @param label A label to put before the path text or null to no label + */ + public FileChooser(IContainer container, Composite parent, int style, String label) + { + // call constructor + this(parent, style, label); + // assign container + this.container = container; + } + + /** + * Setup this composite layout + */ + private void setupLayout() + { + GridLayout layout = new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + this.setLayout(layout); + this.setLayoutData(new GridData(GridData.FILL_BOTH)); + } + + private void createFields() + { + GridData gridData; + if (label != null) + { + fileLabel = new Label(this, SWT.NONE); + fileLabel.setText(label); + gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + fileLabel.setLayoutData(gridData); + } + + pathWidget = new Text(this, SWT.BORDER); + gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, label != null ? 1 : 2, 1); + pathWidget.setLayoutData(gridData); + + Composite buttonsComposite = new Composite(this, SWT.NONE); + gridData = new GridData(SWT.RIGHT, SWT.CENTER, true, false, 2, 1); + buttonsComposite.setLayoutData(gridData); + buttonsComposite.setLayout(new RowLayout(SWT.HORIZONTAL)); + + filesystem = new Button(buttonsComposite, SWT.PUSH); + filesystem.setLayoutData(new RowData()); + filesystem.setText(UtilitiesNLS.UI_FileChooser_Filesystem); + filesystem.addSelectionListener(new SelectionListener() + { + + public void widgetSelected(SelectionEvent e) + { + FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN); + fileDialog.setFilterExtensions(extensionFilter); + fileDialog.setFilterPath(pathWidget.getText()); + String returnedPath = fileDialog.open(); + if (returnedPath != null) + { + pathWidget.setText(returnedPath); + } + } + + public void widgetDefaultSelected(SelectionEvent e) + { + //do nothing + } + }); + + workspace = new Button(buttonsComposite, SWT.PUSH); + workspace.setLayoutData(new RowData()); + workspace.setText(UtilitiesNLS.UI_FileChooser_Workspace); + workspace.addSelectionListener(new SelectionListener() + { + + public void widgetSelected(SelectionEvent e) + { + ElementTreeSelectionDialog dialog = + new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), + new WorkbenchContentProvider()); + dialog.setTitle(UtilitiesNLS.UI_FileChooser_Dialog_Title); + dialog.setMessage(UtilitiesNLS.UI_FileChooser_Dialog_Message); + // set the input depending whether the container exists + if (container != null) + { + // the container exists, set it as the limit + dialog.setInput(container); + } + else + { + // the container does not exists, set the workspace as the limit + dialog.setInput(ResourcesPlugin.getWorkspace().getRoot()); + } + dialog.setComparator(new ResourceComparator(ResourceComparator.NAME)); + //filter extensions + dialog.addFilter(new ViewerFilter() + { + + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) + { + boolean filtered = false; + + if ((extensionFilter != null) && (element instanceof IFile)) + { + IFile file = (IFile) element; + int i = 0; + while ((i < extensionFilter.length) && !filtered) + { + String fileExtensionToShow = + extensionFilter[i].substring(extensionFilter[i] + .lastIndexOf(".") + 1); + String fileExtension = file.getFileExtension(); + if ((fileExtension != null) + && !fileExtension.equals(fileExtensionToShow)) //$NON-NLS-1$ + { + filtered = true; + } + i++; + } + + } + return !filtered; + } + }); + //user can select only one FILE + dialog.setValidator(new ISelectionStatusValidator() + { + + public IStatus validate(Object[] selection) + { + IStatus valid = new Status(IStatus.ERROR, CommonPlugin.PLUGIN_ID, ""); //$NON-NLS-1$ + if (selection.length == 1) + { + if (selection[0] instanceof IFile) + { + valid = new Status(IStatus.OK, CommonPlugin.PLUGIN_ID, ""); //$NON-NLS-1$ + } + } + return valid; + } + }); + + if (dialog.open() == IDialogConstants.OK_ID) + { + IResource resource = (IResource) dialog.getFirstResult(); + pathWidget.setText(resource.getLocation().toOSString()); + } + } + + public void widgetDefaultSelected(SelectionEvent e) + { + //do nothing + } + }); + + } + + /* + * (non-Javadoc) + * @see org.eclipse.swt.widgets.Control#setEnabled(boolean) + */ + @Override + public void setEnabled(boolean enabled) + { + super.setEnabled(enabled); + if (fileLabel != null) + { + fileLabel.setEnabled(enabled); + } + workspace.setEnabled(enabled); + filesystem.setEnabled(enabled); + pathWidget.setEnabled(enabled); + } + + /** + * + * @return the text with the path of the file selected + */ + public String getText() + { + return pathWidget.getText(); + } + + /* + * (non-Javadoc) + * @see org.eclipse.swt.widgets.FileDialog#setFilterExtensions(String[]) + */ + public void setFilterExtensions(String[] filter) + { + extensionFilter = filter; + } + + public void setText(String text) + { + pathWidget.setText(text); + } + + /** + * Add modify text listener + * @param modifyListener + */ + public void addModifyListener(ModifyListener modifyListener) + { + pathWidget.addModifyListener(modifyListener); + } + + /** + * Sets the container. + * @param container + */ + public void setContainer(IContainer container) + { + this.container = container; + } + +} diff --git a/src/plugins/common/src/com/motorola/studio/android/wizards/elements/IBaseBlock.java b/src/plugins/common/src/com/motorola/studio/android/wizards/elements/IBaseBlock.java new file mode 100644 index 0000000..7b3adb9 --- /dev/null +++ b/src/plugins/common/src/com/motorola/studio/android/wizards/elements/IBaseBlock.java @@ -0,0 +1,81 @@ +/*
+* Copyright (C) 2012 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package com.motorola.studio.android.wizards.elements;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Base interface to create a screen block.
+ */
+public interface IBaseBlock extends Listener
+{
+
+ /**
+ * Create the content.
+ */
+ Composite createContent(Composite parent);
+
+ /**
+ * This method must be invoked when the user wants to refresh the screen.
+ */
+ void refresh();
+
+ /**
+ * Returns <code>true</code> if the user can finish the wizard. This is used
+ * when the block is used in wizards.
+ */
+ boolean isPageComplete();
+
+ /**
+ * Returns the error message in this block, null if there is no error.
+ */
+ String getErrorMessage();
+
+ /**
+ * Configures the shell used by this block.
+ *
+ * @param shell The shell.
+ */
+ void setShell(Shell shell);
+
+ /**
+ * Returns the shell used by this block.
+ *
+ * @return Rhe shell used by this block.
+ */
+ Shell getShell();
+
+ /**
+ * Returns <code>true</code> if the user can flip to the next page. This is
+ * used when the block is used in wizards.
+ */
+ boolean canFlipToNextPage();
+
+ /**
+ * Sets the widget that will receive focus when {@link IBaseBlock#setFocus()} is called on the first time the block is visible.
+ * */
+ void setDefaultFocus();
+
+ /**
+ * Sets the focus on the default widget with the block.
+ * This method should call {@link Control#setFocus()} on one of its control widget, for instance a {@link Text} control.
+ * */
+ void setFocus();
+}
diff --git a/src/plugins/common/src/com/motorola/studio/android/wizards/elements/InputRemoveButtons.java b/src/plugins/common/src/com/motorola/studio/android/wizards/elements/InputRemoveButtons.java new file mode 100644 index 0000000..c8b6e67 --- /dev/null +++ b/src/plugins/common/src/com/motorola/studio/android/wizards/elements/InputRemoveButtons.java @@ -0,0 +1,107 @@ +/* +* Copyright (C) 2012 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.motorola.studio.android.wizards.elements; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import com.motorola.studio.android.common.utilities.i18n.UtilitiesNLS; + +/** + * Input and Remove buttons for wizards. + */ +public class InputRemoveButtons extends Composite +{ + private Button inputButton; + + private Button removeButton; + + /** + * Create Input and Remove buttons for wizards. + * @param parent + */ + public InputRemoveButtons(Composite parent) + { + super(parent, SWT.NONE); + createContents(); + } + + /** + * Create Contents + */ + protected void createContents() + { + GridData gridData; + GridLayout gridLayout = new GridLayout(); + gridLayout.marginWidth = 0; + gridLayout.marginHeight = 0; + setLayout(gridLayout); + gridData = new GridData(); + gridData.verticalAlignment = GridData.BEGINNING; + + setLayoutData(gridData); + + createInputButton(); + + //Separator + Label separator = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL); + separator.setFont(getFont()); + separator.setVisible(false); + GridData gd = new GridData(); + gd.horizontalAlignment = GridData.FILL; + gd.verticalAlignment = GridData.BEGINNING; + gd.verticalIndent = 4; + separator.setLayoutData(gd); + // Separator + + createRemoveButton(); + } + + private void createInputButton() + { + inputButton = new Button(this, SWT.PUSH); + inputButton.setText(UtilitiesNLS.AddInputRemoveButtons_InputButtonLabel); + } + + protected void createRemoveButton() + { + removeButton = new Button(this, SWT.PUSH); + removeButton.setText(UtilitiesNLS.UI_AddRemoveButtons_RemoveButtonLabel); + } + + /** + * Return the Input button instance. + * @return the Input button instance + */ + public Button getInputButton() + { + return inputButton; + } + + /** + * Return the Remove button instance. + * @return the Remove button instance + */ + public Button getRemoveButton() + { + return removeButton; + } + +} diff --git a/src/plugins/common/src/com/motorola/studio/android/wizards/elements/ProjectChooser.java b/src/plugins/common/src/com/motorola/studio/android/wizards/elements/ProjectChooser.java new file mode 100644 index 0000000..233742b --- /dev/null +++ b/src/plugins/common/src/com/motorola/studio/android/wizards/elements/ProjectChooser.java @@ -0,0 +1,290 @@ +/*
+* Copyright (C) 2012 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package com.motorola.studio.android.wizards.elements;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+import org.eclipse.ui.dialogs.ISelectionStatusValidator;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.eclipse.ui.views.navigator.ResourceComparator;
+
+import com.motorola.studio.android.common.CommonPlugin;
+import com.motorola.studio.android.common.utilities.i18n.UtilitiesNLS;
+
+/**
+ * This widget displays a Project Chooser element.
+ */
+public class ProjectChooser extends Composite
+{
+
+ private Label lblProject;
+
+ private Text txtProject;
+
+ private Button btnBrowseProject;
+
+ IProject project;
+
+ /**
+ * Get the selected Project.
+ *
+ * @return The selected Project
+ */
+ public IProject getProject()
+ {
+ // get root workspace
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ // get projects
+ IProject[] projects = workspaceRoot.getProjects();
+
+ // iterate through the projects
+ if ((projects != null) && (projects.length > 0))
+ {
+ for (IProject innerProject : projects)
+ {
+ if (innerProject.getName().equals(txtProject.getText()))
+ {
+ // the project was found, set it
+ this.project = innerProject;
+ break;
+ }
+ }
+ }
+ // return the project
+ return project;
+ }
+
+ /**
+ * Get the text filled in the Project´s text field.
+ *
+ * @return The text filled in the Project´s text field
+ */
+ public String getText()
+ {
+ return txtProject != null ? txtProject.getText() : ""; //$NON-NLS-1$
+ }
+
+ /**
+ * Set the text within this {@link ProjectChooser}.
+ *
+ * @param text The text to set
+ */
+ public void setText(String text)
+ {
+ if (txtProject != null)
+ {
+ this.txtProject.setText(text);
+ }
+ }
+
+ /**
+ * Add a modify listener to the Project´s text field. This listener
+ * is called every time the text is modified.
+ *
+ * @param modifyListener Listener to be added
+ *
+ * @see Text#addModifyListener(ModifyListener)
+ */
+ public void addModifyListener(ModifyListener modifyListener)
+ {
+ // add listener
+ txtProject.addModifyListener(modifyListener);
+ }
+
+ /**
+ * Enables or disables the text field.
+ *
+ * @param enabled <code>true</code> in case the Text Field is to
+ * be enabled, <code>false</code> otherwise.
+ */
+ public void setTextFieldEnabled(boolean enabled)
+ {
+ // enables/disables the text field
+ txtProject.setEnabled(enabled);
+ }
+
+ /**
+ * Constructor holding the parent composite and the stile.
+ *
+ * @param parent Parent Composite
+ * @param style Style
+ */
+ public ProjectChooser(Composite parent, int style)
+ {
+ // call super
+ super(parent, style);
+ // set up layout
+ setupLayout();
+ // add components
+ addComponents();
+ }
+
+ /**
+ * Set up this widget layout
+ */
+ private void setupLayout()
+ {
+ GridLayout layout = new GridLayout(5, false);
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ this.setLayout(layout);
+ this.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+ }
+
+ /**
+ * Add components to this widget
+ */
+ private void addComponents()
+ {
+ // add project label
+ lblProject = new Label(this, SWT.NONE);
+ lblProject.setText(UtilitiesNLS.UI_General_ProjectLabel);
+ lblProject.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 1, 1));
+
+ // add text field
+ txtProject = new Text(this, SWT.BORDER);
+ txtProject.setText(""); //$NON-NLS-1$
+ txtProject.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 3, 1));
+
+ // add browner button
+ btnBrowseProject = new Button(this, SWT.PUSH);
+ btnBrowseProject.setText(UtilitiesNLS.UI_General_BrowseButtonLabel);
+ btnBrowseProject.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false,
+ 1, 1));
+
+ btnBrowseProject.addListener(SWT.Selection, new Listener()
+ {
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
+ */
+
+ public void handleEvent(Event event)
+ {
+ // get the selected project
+ project = openProjectChooser();
+ // write the project in case there is one
+ if (project != null)
+ {
+ txtProject.setText(project.getName());
+ }
+ }
+ });
+ }
+
+ /**
+ * Opens dialog to choose a project
+ *
+ * @return Selected project
+ */
+ private IProject openProjectChooser()
+ {
+ IProject selectedProject = null;
+
+ // get shell
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ // crate package dialog
+ final ElementTreeSelectionDialog packageDialog =
+ new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(),
+ new WorkbenchContentProvider());
+
+ // set title and message
+ packageDialog.setTitle(UtilitiesNLS.ProjectChooser_UI_Selection);
+ packageDialog.setMessage(UtilitiesNLS.ProjectChooser_UI_ChooseAProject);
+
+ // set workspace as root
+ packageDialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
+ // set comparator
+ packageDialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
+
+ //filter extensions
+ packageDialog.addFilter(new ViewerFilter()
+ {
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element)
+ {
+ // the element must be a project
+ return element instanceof IProject;
+ }
+ });
+ //user can select only one PROJECT
+ packageDialog.setValidator(new ISelectionStatusValidator()
+ {
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.dialogs.ISelectionStatusValidator#validate(java.lang.Object[])
+ */
+
+ public IStatus validate(Object[] selection)
+ {
+ // by default the status is an error
+ IStatus valid = new Status(IStatus.ERROR, CommonPlugin.PLUGIN_ID, ""); //$NON-NLS-1$
+ // one element must be selected
+ if (selection.length == 1)
+ {
+ // this element must be a project
+ if (selection[0] instanceof IProject)
+ {
+ // set status to valid because it is one element and a project
+ valid = new Status(IStatus.OK, CommonPlugin.PLUGIN_ID, ""); //$NON-NLS-1$
+ }
+ }
+ // return validation
+ return valid;
+ }
+ });
+ // open dialog
+ if (packageDialog.open() == IDialogConstants.OK_ID)
+ {
+ // get the first result
+ IResource resource = (IResource) packageDialog.getFirstResult();
+ // the resource must be a project
+ if (resource instanceof IProject)
+ {
+ // get the selected project
+ selectedProject = (IProject) resource;
+ }
+ }
+ // return the selected project
+ return selectedProject;
+ }
+}
|