package com.android.ide.eclipse.adt.internal.assetstudio;
-import com.android.ide.eclipse.adt.internal.project.ProjectChooserHelper.ProjectButton;
+import com.android.ide.eclipse.adt.internal.project.ProjectChooserHelper;
+import com.android.ide.eclipse.adt.internal.project.ProjectChooserHelper.ProjectCombo;
import com.android.ide.eclipse.adt.internal.resources.ResourceNameValidator;
import com.android.resources.ResourceFolderType;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
/** Page for choosing the type of asset to create, as well as the target project */
public class ChooseAssetTypePage extends WizardPage implements SelectionListener, ModifyListener {
- private ProjectButton mProjectButton;
+ private ProjectCombo mProjectButton;
private Button mClipboardButton;
private IProject mProject;
private Text mNameText;
projectLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
projectLabel.setText("Project:");
- mProjectButton = new ProjectButton(container, mProject);
- mProjectButton.setAlignment(SWT.LEFT);
+ ProjectChooserHelper helper =
+ new ProjectChooserHelper(getShell(), null /* filter */);
+ mProjectButton = new ProjectCombo(helper, container, mProject);
mProjectButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
mProjectButton.addSelectionListener(this);
resourceLabel.setText("Resource:");
mResourceName = new Label(container, SWT.NONE);
- mResourceName.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
+ mResourceName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
mClipboardButton = new Button(container, SWT.FLAT);
mClipboardButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
if (source == mProjectButton) {
mProject = mProjectButton.getSelectedProject();
validatePage();
+ } else if (source == mClipboardButton) {
+ Clipboard clipboard = new Clipboard(getShell().getDisplay());
+ TextTransfer textTransfer = TextTransfer.getInstance();
+ clipboard.setContents(
+ new Object[] { mResourceName.getText() },
+ new Transfer[] { textTransfer });
+ clipboard.dispose();
} else if (source instanceof Button) {
// User selected a different asset type to be created
Object data = ((Button) source).getData();
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
/**
}
/**
- * A selector button for showing the currently selected project and for
+ * A selector combo for showing the currently selected project and for
* changing the selection
*/
- public static class ProjectButton extends Button implements SelectionListener {
+ public static class ProjectCombo extends Combo implements SelectionListener {
/** Currently chosen project, or null when no project has been initialized or selected */
private IProject mProject;
+ private IJavaProject[] mAvailableProjects;
/**
- * Creates a new project selector button
+ * Creates a new project selector combo
*
- * @param parent parent composite to add the button to
+ * @param helper associated {@link ProjectChooserHelper} for looking up
+ * projects
+ * @param parent parent composite to add the combo to
* @param initialProject the initial project to select, or null (which
* will show a "Please Choose Project..." label instead.)
*/
- public ProjectButton(Composite parent, IProject initialProject) {
- super(parent, SWT.BORDER | SWT.FLAT);
+ public ProjectCombo(ProjectChooserHelper helper, Composite parent,
+ IProject initialProject) {
+ super(parent, SWT.BORDER | SWT.FLAT | SWT.READ_ONLY);
mProject = initialProject;
- setProjectLabel(initialProject);
+
+ mAvailableProjects = helper.getAndroidProjects(null);
+ String[] items = new String[mAvailableProjects.length + 1];
+ items[0] = "--- Choose Project ---";
+
+ ILabelProvider labelProvider = new JavaElementLabelProvider(
+ JavaElementLabelProvider.SHOW_DEFAULT);
+ int selectionIndex = 0;
+ for (int i = 0, n = mAvailableProjects.length; i < n; i++) {
+ IProject project = mAvailableProjects[i].getProject();
+ items[i + 1] = labelProvider.getText(project);
+ if (project == initialProject) {
+ selectionIndex = i + 1;
+ }
+ }
+ setItems(items);
+ select(selectionIndex);
+
addSelectionListener(this);
}
*/
public void setSelectedProject(IProject project) {
mProject = project;
- setProjectLabel(project);
- }
-
- /** Updates the selection with the given project */
- private void setProjectLabel(IProject project) {
- ILabelProvider labelProvider = new JavaElementLabelProvider(
- JavaElementLabelProvider.SHOW_DEFAULT);
- if (project == null) {
- setText("Choose Project...");
- ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
- Image errorImage = sharedImages.getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
- setImage(errorImage);
- } else {
- setText(labelProvider.getText(project));
- Image projectImage = labelProvider.getImage(project);
- if (projectImage != null) {
- setImage(projectImage);
- }
- }
}
/**
* dialog for selecting a new project.
*/
public void widgetSelected(SelectionEvent e) {
- ProjectChooserHelper helper =
- new ProjectChooserHelper(getShell(), null /* filter */);
- IJavaProject p = helper.chooseJavaProject(getText(),
- "Please select the target project");
- if (p != null) {
- mProject = p.getProject();
- setProjectLabel(mProject);
+ int selectionIndex = getSelectionIndex();
+ if (selectionIndex > 0 && mAvailableProjects != null
+ && selectionIndex <= mAvailableProjects.length) {
+ // selection index 0 is "Choose Project", all other projects are offset
+ // by 1 from the selection index
+ mProject = mAvailableProjects[selectionIndex - 1].getProject();
+ } else {
+ mProject = null;
}
}
import com.android.ide.eclipse.adt.internal.editors.resources.descriptors.ResourcesDescriptors;
import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper;
import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper.IProjectFilter;
-import com.android.ide.eclipse.adt.internal.project.ProjectChooserHelper.ProjectButton;
+import com.android.ide.eclipse.adt.internal.project.ProjectChooserHelper;
+import com.android.ide.eclipse.adt.internal.project.ProjectChooserHelper.ProjectCombo;
import com.android.ide.eclipse.adt.internal.resources.ResourceNameValidator;
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
import com.android.ide.eclipse.adt.internal.sdk.Sdk;
};
private NewXmlFileWizard.Values mValues;
- private ProjectButton mProjectButton;
+ private ProjectCombo mProjectButton;
private Text mFileNameTextField;
private Combo mTypeCombo;
private IStructuredSelection mInitialSelection;
projectLabel.setText("Project:");
projectLabel.setToolTipText(tooltip);
- mProjectButton = new ProjectButton(composite, mValues.project);
+ ProjectChooserHelper helper =
+ new ProjectChooserHelper(getShell(), null /* filter */);
+
+ mProjectButton = new ProjectCombo(helper, composite, mValues.project);
mProjectButton.setToolTipText(tooltip);
- mProjectButton.setAlignment(SWT.LEFT);
mProjectButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
mProjectButton.addSelectionListener(new SelectionAdapter() {
@Override
// enable types based on new API level
updateAvailableTypes();
+ initialSelectType();
// update the folder name based on API level
updateFolderPath(mValues.type);
String error = null;
String warning = null;
- // -- validate project
- if (mValues.project == null) {
- error = "Please select an Android project.";
- }
-
// -- validate type
TypeInfo type = mValues.type;
if (error == null) {
}
}
- // -- validate filename
- if (error == null) {
- String fileName = mValues.getFileName();
- assert type != null;
- ResourceFolderType folderType = type.getResFolderType();
- error = ResourceNameValidator.create(true, folderType).isValid(fileName);
+ // -- validate project
+ if (mValues.project == null) {
+ error = "Please select an Android project.";
}
// -- validate type API level
}
}
+ // -- validate filename
+ if (error == null) {
+ String fileName = mValues.getFileName();
+ assert type != null;
+ ResourceFolderType folderType = type.getResFolderType();
+ error = ResourceNameValidator.create(true, folderType).isValid(fileName);
+ }
+
// -- validate destination file doesn't exist
if (error == null) {
IFile file = mValues.getDestinationFile();