From ee76a2912fa5611f18dd6d46d7ed4c7b6037bbb8 Mon Sep 17 00:00:00 2001 From: Raphael Moll <> Date: Tue, 31 Mar 2009 17:27:19 -0700 Subject: AI 143886: am: CL 143882 ADT #1743364: Refactor misc UI widgets together in package adt.ui. Original author: raphael Merged from: //branches/cupcake/... Automated import of CL 143886 --- .../META-INF/MANIFEST.MF | 2 +- .../src/com/android/ide/eclipse/adt/AdtPlugin.java | 2 +- .../extractstring/ExtractStringInputPage.java | 2 +- .../ide/eclipse/adt/ui/ConfigurationSelector.java | 1278 ++++++++++++++++++++ .../ide/eclipse/adt/ui/EclipseUiHelper.java | 64 + .../ide/eclipse/adt/ui/ReferenceChooserDialog.java | 266 ++++ .../ide/eclipse/adt/ui/ResourceChooser.java | 193 +++ .../eclipse/adt/ui/ResourceContentProvider.java | 110 ++ .../ide/eclipse/adt/ui/ResourceLabelProvider.java | 138 +++ .../wizards/newxmlfile/NewXmlFileCreationPage.java | 4 +- .../ide/eclipse/common/EclipseUiHelper.java | 64 - .../editors/layout/GraphicalLayoutEditor.java | 8 +- .../editors/layout/LayoutCreatorDialog.java | 4 +- .../ide/eclipse/editors/layout/LayoutEditor.java | 2 +- .../editors/layout/UiContentOutlinePage.java | 2 +- .../resources/explorer/ResourceExplorerView.java | 4 +- .../editors/uimodel/UiResourceAttributeNode.java | 4 +- .../editors/wizards/ConfigurationSelector.java | 1278 -------------------- .../editors/wizards/ReferenceChooserDialog.java | 266 ---- .../eclipse/editors/wizards/ResourceChooser.java | 193 --- .../editors/wizards/ResourceContentProvider.java | 110 -- .../editors/wizards/ResourceLabelProvider.java | 138 --- 22 files changed, 2066 insertions(+), 2066 deletions(-) create mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ConfigurationSelector.java create mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/EclipseUiHelper.java create mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ReferenceChooserDialog.java create mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ResourceChooser.java create mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ResourceContentProvider.java create mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ResourceLabelProvider.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/EclipseUiHelper.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ConfigurationSelector.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ReferenceChooserDialog.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ResourceChooser.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ResourceContentProvider.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ResourceLabelProvider.java diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/META-INF/MANIFEST.MF b/eclipse/plugins/com.android.ide.eclipse.adt/META-INF/MANIFEST.MF index 0ec97aa..4b9d3a0 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/META-INF/MANIFEST.MF +++ b/eclipse/plugins/com.android.ide.eclipse.adt/META-INF/MANIFEST.MF @@ -52,6 +52,7 @@ Export-Package: com.android.ide.eclipse.adt;x-friends:="com.android.ide.eclipse. com.android.ide.eclipse.adt.project.internal;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.sdk;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.wizards.newproject;x-friends:="com.android.ide.eclipse.tests", + com.android.ide.eclipse.adt.ui;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.common;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.common.project;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.common.resources;x-friends:="com.android.ide.eclipse.tests", @@ -77,7 +78,6 @@ Export-Package: com.android.ide.eclipse.adt;x-friends:="com.android.ide.eclipse. com.android.ide.eclipse.editors.ui;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.editors.ui.tree;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.editors.uimodel;x-friends:="com.android.ide.eclipse.tests", - com.android.ide.eclipse.editors.wizards;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.editors.xml;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.editors.xml.descriptors;x-friends:="com.android.ide.eclipse.tests" diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java index 42db64a..4a7a002 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java @@ -29,8 +29,8 @@ import com.android.ide.eclipse.adt.sdk.AndroidTargetParser; import com.android.ide.eclipse.adt.sdk.LoadStatus; import com.android.ide.eclipse.adt.sdk.Sdk; import com.android.ide.eclipse.adt.sdk.Sdk.ITargetChangeListener; +import com.android.ide.eclipse.adt.ui.EclipseUiHelper; import com.android.ide.eclipse.common.AndroidConstants; -import com.android.ide.eclipse.common.EclipseUiHelper; import com.android.ide.eclipse.common.SdkStatsHelper; import com.android.ide.eclipse.common.StreamHelper; import com.android.ide.eclipse.common.project.BaseProjectHelper; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/refactorings/extractstring/ExtractStringInputPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/refactorings/extractstring/ExtractStringInputPage.java index 5ffeeb0..9822b32 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/refactorings/extractstring/ExtractStringInputPage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/refactorings/extractstring/ExtractStringInputPage.java @@ -17,10 +17,10 @@ package com.android.ide.eclipse.adt.refactorings.extractstring; +import com.android.ide.eclipse.adt.ui.ConfigurationSelector; import com.android.ide.eclipse.common.AndroidConstants; import com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration; import com.android.ide.eclipse.editors.resources.manager.ResourceFolderType; -import com.android.ide.eclipse.editors.wizards.ConfigurationSelector; import com.android.sdklib.SdkConstants; import org.eclipse.core.resources.IFolder; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ConfigurationSelector.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ConfigurationSelector.java new file mode 100644 index 0000000..651d1e0 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ConfigurationSelector.java @@ -0,0 +1,1278 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php + * + * 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.android.ide.eclipse.adt.ui; + +import com.android.ide.eclipse.editors.resources.configurations.CountryCodeQualifier; +import com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration; +import com.android.ide.eclipse.editors.resources.configurations.KeyboardStateQualifier; +import com.android.ide.eclipse.editors.resources.configurations.LanguageQualifier; +import com.android.ide.eclipse.editors.resources.configurations.NavigationMethodQualifier; +import com.android.ide.eclipse.editors.resources.configurations.NetworkCodeQualifier; +import com.android.ide.eclipse.editors.resources.configurations.PixelDensityQualifier; +import com.android.ide.eclipse.editors.resources.configurations.RegionQualifier; +import com.android.ide.eclipse.editors.resources.configurations.ResourceQualifier; +import com.android.ide.eclipse.editors.resources.configurations.ScreenDimensionQualifier; +import com.android.ide.eclipse.editors.resources.configurations.ScreenOrientationQualifier; +import com.android.ide.eclipse.editors.resources.configurations.TextInputMethodQualifier; +import com.android.ide.eclipse.editors.resources.configurations.TouchScreenQualifier; +import com.android.ide.eclipse.editors.resources.configurations.KeyboardStateQualifier.KeyboardState; +import com.android.ide.eclipse.editors.resources.configurations.NavigationMethodQualifier.NavigationMethod; +import com.android.ide.eclipse.editors.resources.configurations.ScreenOrientationQualifier.ScreenOrientation; +import com.android.ide.eclipse.editors.resources.configurations.TextInputMethodQualifier.TextInputMethod; +import com.android.ide.eclipse.editors.resources.configurations.TouchScreenQualifier.TouchScreenType; +import com.android.ide.eclipse.editors.resources.manager.ResourceManager; + +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.Text; + +import java.util.HashMap; + +/** + * Custom UI widget to let user build a Folder configuration. + *

+ * To use this, instantiate somewhere in the UI and then: + *

+ */ +public class ConfigurationSelector extends Composite { + + public static final int WIDTH_HINT = 600; + public static final int HEIGHT_HINT = 250; + + private Runnable mOnChangeListener; + + private TableViewer mFullTableViewer; + private TableViewer mSelectionTableViewer; + private Button mAddButton; + private Button mRemoveButton; + private StackLayout mStackLayout; + + private boolean mOnRefresh = false; + + private final FolderConfiguration mBaseConfiguration = new FolderConfiguration(); + private final FolderConfiguration mSelectedConfiguration = new FolderConfiguration(); + + private final HashMap, QualifierEditBase> mUiMap = + new HashMap, QualifierEditBase>(); + private Composite mQualifierEditParent; + + /** + * Basic of {@link VerifyListener} to only accept digits. + */ + private static class DigitVerifier implements VerifyListener { + public void verifyText(VerifyEvent e) { + // check for digit only. + for (int i = 0 ; i < e.text.length(); i++) { + char letter = e.text.charAt(i); + if (letter < '0' || letter > '9') { + e.doit = false; + return; + } + } + } + } + + /** + * Implementation of {@link VerifyListener} for Country Code qualifiers. + */ + public static class MobileCodeVerifier extends DigitVerifier { + @Override + public void verifyText(VerifyEvent e) { + super.verifyText(e); + + // basic tests passed? + if (e.doit) { + // check the max 3 digits. + if (e.text.length() - e.end + e.start + + ((Text)e.getSource()).getText().length() > 3) { + e.doit = false; + } + } + } + } + + /** + * Implementation of {@link VerifyListener} for the Language and Region qualifiers. + */ + public static class LanguageRegionVerifier implements VerifyListener { + public void verifyText(VerifyEvent e) { + // check for length + if (e.text.length() - e.end + e.start + ((Combo)e.getSource()).getText().length() > 2) { + e.doit = false; + return; + } + + // check for lower case only. + for (int i = 0 ; i < e.text.length(); i++) { + char letter = e.text.charAt(i); + if ((letter < 'a' || letter > 'z') && (letter < 'A' || letter > 'Z')) { + e.doit = false; + return; + } + } + } + } + + /** + * Implementation of {@link VerifyListener} for the Pixel Density qualifier. + */ + public static class DensityVerifier extends DigitVerifier { } + + /** + * Implementation of {@link VerifyListener} for the Screen Dimension qualifier. + */ + public static class DimensionVerifier extends DigitVerifier { } + + /** + * Enum for the state of the configuration being created. + */ + public enum ConfigurationState { + OK, INVALID_CONFIG, REGION_WITHOUT_LANGUAGE; + } + + public ConfigurationSelector(Composite parent) { + super(parent, SWT.NONE); + + mBaseConfiguration.createDefault(); + + GridLayout gl = new GridLayout(4, false); + gl.marginWidth = gl.marginHeight = 0; + setLayout(gl); + + // first column is the first table + final Table fullTable = new Table(this, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER); + fullTable.setLayoutData(new GridData(GridData.FILL_BOTH)); + fullTable.setHeaderVisible(true); + fullTable.setLinesVisible(true); + + // create the column + final TableColumn fullTableColumn = new TableColumn(fullTable, SWT.LEFT); + // set the header + fullTableColumn.setText("Available Qualifiers"); + + fullTable.addControlListener(new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + Rectangle r = fullTable.getClientArea(); + fullTableColumn.setWidth(r.width); + } + }); + + mFullTableViewer = new TableViewer(fullTable); + mFullTableViewer.setContentProvider(new QualifierContentProvider()); + mFullTableViewer.setLabelProvider(new QualifierLabelProvider( + false /* showQualifierValue */)); + mFullTableViewer.setInput(mBaseConfiguration); + mFullTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + ISelection selection = event.getSelection(); + if (selection instanceof IStructuredSelection) { + IStructuredSelection structSelection = (IStructuredSelection)selection; + Object first = structSelection.getFirstElement(); + + if (first instanceof ResourceQualifier) { + mAddButton.setEnabled(true); + return; + } + } + + mAddButton.setEnabled(false); + } + }); + + // 2nd column is the left/right arrow button + Composite buttonComposite = new Composite(this, SWT.NONE); + gl = new GridLayout(1, false); + gl.marginWidth = gl.marginHeight = 0; + buttonComposite.setLayout(gl); + buttonComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); + + new Composite(buttonComposite, SWT.NONE); + mAddButton = new Button(buttonComposite, SWT.BORDER | SWT.PUSH); + mAddButton.setText("->"); + mAddButton.setEnabled(false); + mAddButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + IStructuredSelection selection = + (IStructuredSelection)mFullTableViewer.getSelection(); + + Object first = selection.getFirstElement(); + if (first instanceof ResourceQualifier) { + ResourceQualifier qualifier = (ResourceQualifier)first; + + mBaseConfiguration.removeQualifier(qualifier); + mSelectedConfiguration.addQualifier(qualifier); + + mFullTableViewer.refresh(); + mSelectionTableViewer.refresh(); + mSelectionTableViewer.setSelection(new StructuredSelection(qualifier), true); + + onChange(false /* keepSelection */); + } + } + }); + + mRemoveButton = new Button(buttonComposite, SWT.BORDER | SWT.PUSH); + mRemoveButton.setText("<-"); + mRemoveButton.setEnabled(false); + mRemoveButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + IStructuredSelection selection = + (IStructuredSelection)mSelectionTableViewer.getSelection(); + + Object first = selection.getFirstElement(); + if (first instanceof ResourceQualifier) { + ResourceQualifier qualifier = (ResourceQualifier)first; + + mSelectedConfiguration.removeQualifier(qualifier); + mBaseConfiguration.addQualifier(qualifier); + + mFullTableViewer.refresh(); + mSelectionTableViewer.refresh(); + + onChange(false /* keepSelection */); + } + } + }); + + // 3rd column is the selected config table + final Table selectionTable = new Table(this, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER); + selectionTable.setLayoutData(new GridData(GridData.FILL_BOTH)); + selectionTable.setHeaderVisible(true); + selectionTable.setLinesVisible(true); + + // create the column + final TableColumn selectionTableColumn = new TableColumn(selectionTable, SWT.LEFT); + // set the header + selectionTableColumn.setText("Chosen Qualifiers"); + + selectionTable.addControlListener(new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + Rectangle r = selectionTable.getClientArea(); + selectionTableColumn.setWidth(r.width); + } + }); + mSelectionTableViewer = new TableViewer(selectionTable); + mSelectionTableViewer.setContentProvider(new QualifierContentProvider()); + mSelectionTableViewer.setLabelProvider(new QualifierLabelProvider( + true /* showQualifierValue */)); + mSelectionTableViewer.setInput(mSelectedConfiguration); + mSelectionTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + // ignore selection changes during resfreshes in some cases. + if (mOnRefresh) { + return; + } + + ISelection selection = event.getSelection(); + if (selection instanceof IStructuredSelection) { + IStructuredSelection structSelection = (IStructuredSelection)selection; + + if (structSelection.isEmpty() == false) { + Object first = structSelection.getFirstElement(); + + if (first instanceof ResourceQualifier) { + mRemoveButton.setEnabled(true); + + QualifierEditBase composite = mUiMap.get(first.getClass()); + + if (composite != null) { + composite.setQualifier((ResourceQualifier)first); + } + + mStackLayout.topControl = composite; + mQualifierEditParent.layout(); + + return; + } + } else { + mStackLayout.topControl = null; + mQualifierEditParent.layout(); + } + } + + mRemoveButton.setEnabled(false); + } + }); + + // 4th column is the detail of the selected qualifier + mQualifierEditParent = new Composite(this, SWT.NONE); + mQualifierEditParent.setLayout(mStackLayout = new StackLayout()); + mQualifierEditParent.setLayoutData(new GridData(GridData.FILL_VERTICAL)); + + // create the UI for all the qualifiers, and associate them to the ResourceQualifer class. + mUiMap.put(CountryCodeQualifier.class, new MCCEdit(mQualifierEditParent)); + mUiMap.put(NetworkCodeQualifier.class, new MNCEdit(mQualifierEditParent)); + mUiMap.put(LanguageQualifier.class, new LanguageEdit(mQualifierEditParent)); + mUiMap.put(RegionQualifier.class, new RegionEdit(mQualifierEditParent)); + mUiMap.put(ScreenOrientationQualifier.class, new OrientationEdit(mQualifierEditParent)); + mUiMap.put(PixelDensityQualifier.class, new PixelDensityEdit(mQualifierEditParent)); + mUiMap.put(TouchScreenQualifier.class, new TouchEdit(mQualifierEditParent)); + mUiMap.put(KeyboardStateQualifier.class, new KeyboardEdit(mQualifierEditParent)); + mUiMap.put(TextInputMethodQualifier.class, new TextInputEdit(mQualifierEditParent)); + mUiMap.put(NavigationMethodQualifier.class, new NavigationEdit(mQualifierEditParent)); + mUiMap.put(ScreenDimensionQualifier.class, new ScreenDimensionEdit(mQualifierEditParent)); + } + + /** + * Sets a listener to be notified when the configuration changes. + * @param listener A {@link Runnable} whose run() method is called when the + * configuration is changed. The method is called from the UI thread. + */ + public void setOnChangeListener(Runnable listener) { + mOnChangeListener = listener; + } + + /** + * Initialize the UI with a given {@link FolderConfiguration}. This must + * be called from the UI thread. + * @param config The configuration. + */ + public void setConfiguration(FolderConfiguration config) { + mSelectedConfiguration.set(config); + mSelectionTableViewer.refresh(); + + // create the base config, which is the default config minus the qualifiers + // in SelectedConfiguration + mBaseConfiguration.substract(mSelectedConfiguration); + mFullTableViewer.refresh(); + } + + /** + * Initialize the UI with the configuration represented by a resource folder name. + * This must be called from the UI thread. + * + * @param folderSegments the segments of the folder name, + * split using {@link FolderConfiguration#QUALIFIER_SEP}. + * @return true if success, or false if the folder name is not a valid name. + */ + public boolean setConfiguration(String[] folderSegments) { + FolderConfiguration config = ResourceManager.getInstance().getConfig(folderSegments); + + if (config == null) { + return false; + } + + setConfiguration(config); + + return true; + } + + /** + * Initialize the UI with the configuration represented by a resource folder name. + * This must be called from the UI thread. + * @param folderName the name of the folder. + * @return true if success, or false if the folder name is not a valid name. + */ + public boolean setConfiguration(String folderName) { + // split the name of the folder in segments. + String[] folderSegments = folderName.split(FolderConfiguration.QUALIFIER_SEP); + + return setConfiguration(folderSegments); + } + + /** + * Gets the configuration as setup by the widget. + * @param config the {@link FolderConfiguration} object to be filled with the information + * from the UI. + */ + public void getConfiguration(FolderConfiguration config) { + config.set(mSelectedConfiguration); + } + + /** + * Returns the state of the configuration being edited/created. + */ + public ConfigurationState getState() { + if (mSelectedConfiguration.getInvalidQualifier() != null) { + return ConfigurationState.INVALID_CONFIG; + } + + if (mSelectedConfiguration.checkRegion() == false) { + return ConfigurationState.REGION_WITHOUT_LANGUAGE; + } + + return ConfigurationState.OK; + } + + /** + * Returns the first invalid qualifier of the configuration being edited/created, + * or null if they are all valid (or if none exists). + *

If {@link #getState()} return {@link ConfigurationState#INVALID_CONFIG} then this will + * not return null. + */ + public ResourceQualifier getInvalidQualifier() { + return mSelectedConfiguration.getInvalidQualifier(); + } + + /** + * Handle changes in the configuration. + * @param keepSelection if true attemps to avoid triggering selection change in + * {@link #mSelectedConfiguration}. + */ + private void onChange(boolean keepSelection) { + ISelection selection = null; + if (keepSelection) { + mOnRefresh = true; + selection = mSelectionTableViewer.getSelection(); + } + + mSelectionTableViewer.refresh(true); + + if (keepSelection) { + mSelectionTableViewer.setSelection(selection); + mOnRefresh = false; + } + + if (mOnChangeListener != null) { + mOnChangeListener.run(); + } + } + + /** + * Content provider around a {@link FolderConfiguration}. + */ + private static class QualifierContentProvider implements IStructuredContentProvider { + + private FolderConfiguration mInput; + + public QualifierContentProvider() { + } + + public void dispose() { + // pass + } + + public Object[] getElements(Object inputElement) { + return mInput.getQualifiers(); + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + mInput = null; + if (newInput instanceof FolderConfiguration) { + mInput = (FolderConfiguration)newInput; + } + } + } + + /** + * Label provider for {@link ResourceQualifier} objects. + */ + private static class QualifierLabelProvider implements ITableLabelProvider { + + private final boolean mShowQualifierValue; + + public QualifierLabelProvider(boolean showQualifierValue) { + mShowQualifierValue = showQualifierValue; + } + + public String getColumnText(Object element, int columnIndex) { + // only one column, so we can ignore columnIndex + if (element instanceof ResourceQualifier) { + if (mShowQualifierValue) { + String value = ((ResourceQualifier)element).getStringValue(); + if (value.length() == 0) { + return String.format("%1$s (?)", + ((ResourceQualifier)element).getShortName()); + } else { + return value; + } + + } else { + return ((ResourceQualifier)element).getShortName(); + } + } + + return null; + } + + public Image getColumnImage(Object element, int columnIndex) { + // only one column, so we can ignore columnIndex + if (element instanceof ResourceQualifier) { + return ((ResourceQualifier)element).getIcon(); + } + + return null; + } + + public void addListener(ILabelProviderListener listener) { + // pass + } + + public void dispose() { + // pass + } + + public boolean isLabelProperty(Object element, String property) { + // pass + return false; + } + + public void removeListener(ILabelProviderListener listener) { + // pass + } + } + + /** + * Base class for Edit widget for {@link ResourceQualifier}. + */ + private abstract static class QualifierEditBase extends Composite { + + public QualifierEditBase(Composite parent, String title) { + super(parent, SWT.NONE); + setLayout(new GridLayout(1, false)); + + new Label(this, SWT.NONE).setText(title); + } + + public abstract void setQualifier(ResourceQualifier qualifier); + } + + /** + * Edit widget for {@link CountryCodeQualifier}. + */ + private class MCCEdit extends QualifierEditBase { + + private Text mText; + + public MCCEdit(Composite parent) { + super(parent, CountryCodeQualifier.NAME); + + mText = new Text(this, SWT.BORDER); + mText.addVerifyListener(new MobileCodeVerifier()); + mText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + onTextChange(); + } + }); + + mText.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + onTextChange(); + } + }); + + new Label(this, SWT.NONE).setText("(3 digit code)"); + } + + private void onTextChange() { + String value = mText.getText(); + + if (value.length() == 0) { + // empty string, means a qualifier with no value. + // Since the qualifier classes are immutable, and we don't want to + // remove the qualifier from the configuration, we create a new default one. + mSelectedConfiguration.setCountryCodeQualifier(new CountryCodeQualifier()); + } else { + try { + CountryCodeQualifier qualifier = CountryCodeQualifier.getQualifier( + CountryCodeQualifier.getFolderSegment(Integer.parseInt(value))); + if (qualifier != null) { + mSelectedConfiguration.setCountryCodeQualifier(qualifier); + } else { + // Failure! Looks like the value is wrong + // (for instance not exactly 3 digits). + mSelectedConfiguration.setCountryCodeQualifier(new CountryCodeQualifier()); + } + } catch (NumberFormatException nfe) { + // Looks like the code is not a number. This should not happen since the text + // field has a VerifyListener that prevents it. + mSelectedConfiguration.setCountryCodeQualifier(new CountryCodeQualifier()); + } + } + + // notify of change + onChange(true /* keepSelection */); + } + + @Override + public void setQualifier(ResourceQualifier qualifier) { + CountryCodeQualifier q = (CountryCodeQualifier)qualifier; + + mText.setText(Integer.toString(q.getCode())); + } + } + + /** + * Edit widget for {@link NetworkCodeQualifier}. + */ + private class MNCEdit extends QualifierEditBase { + private Text mText; + + public MNCEdit(Composite parent) { + super(parent, NetworkCodeQualifier.NAME); + + mText = new Text(this, SWT.BORDER); + mText.addVerifyListener(new MobileCodeVerifier()); + mText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + onTextChange(); + } + }); + mText.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + onTextChange(); + } + }); + + new Label(this, SWT.NONE).setText("(1-3 digit code)"); + } + + private void onTextChange() { + String value = mText.getText(); + + if (value.length() == 0) { + // empty string, means a qualifier with no value. + // Since the qualifier classes are immutable, and we don't want to + // remove the qualifier from the configuration, we create a new default one. + mSelectedConfiguration.setNetworkCodeQualifier(new NetworkCodeQualifier()); + } else { + try { + NetworkCodeQualifier qualifier = NetworkCodeQualifier.getQualifier( + NetworkCodeQualifier.getFolderSegment(Integer.parseInt(value))); + if (qualifier != null) { + mSelectedConfiguration.setNetworkCodeQualifier(qualifier); + } else { + // Failure! Looks like the value is wrong + // (for instance not exactly 3 digits). + mSelectedConfiguration.setNetworkCodeQualifier(new NetworkCodeQualifier()); + } + } catch (NumberFormatException nfe) { + // Looks like the code is not a number. This should not happen since the text + // field has a VerifyListener that prevents it. + mSelectedConfiguration.setNetworkCodeQualifier(new NetworkCodeQualifier()); + } + } + + // notify of change + onChange(true /* keepSelection */); + } + + @Override + public void setQualifier(ResourceQualifier qualifier) { + NetworkCodeQualifier q = (NetworkCodeQualifier)qualifier; + + mText.setText(Integer.toString(q.getCode())); + } + } + + /** + * Edit widget for {@link LanguageQualifier}. + */ + private class LanguageEdit extends QualifierEditBase { + private Combo mLanguage; + + public LanguageEdit(Composite parent) { + super(parent, LanguageQualifier.NAME); + + mLanguage = new Combo(this, SWT.DROP_DOWN); + mLanguage.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + mLanguage.addVerifyListener(new LanguageRegionVerifier()); + mLanguage.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + onLanguageChange(); + } + public void widgetSelected(SelectionEvent e) { + onLanguageChange(); + } + }); + mLanguage.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + onLanguageChange(); + } + }); + + new Label(this, SWT.NONE).setText("(2 letter code)"); + } + + private void onLanguageChange() { + // update the current config + String value = mLanguage.getText(); + + if (value.length() == 0) { + // empty string, means no qualifier. + // Since the qualifier classes are immutable, and we don't want to + // remove the qualifier from the configuration, we create a new default one. + mSelectedConfiguration.setLanguageQualifier(new LanguageQualifier()); + } else { + LanguageQualifier qualifier = null; + String segment = LanguageQualifier.getFolderSegment(value); + if (segment != null) { + qualifier = LanguageQualifier.getQualifier(segment); + } + + if (qualifier != null) { + mSelectedConfiguration.setLanguageQualifier(qualifier); + } else { + // Failure! Looks like the value is wrong (for instance a one letter string). + mSelectedConfiguration.setLanguageQualifier(new LanguageQualifier()); + } + } + + // notify of change + onChange(true /* keepSelection */); + } + + @Override + public void setQualifier(ResourceQualifier qualifier) { + LanguageQualifier q = (LanguageQualifier)qualifier; + + String value = q.getValue(); + if (value != null) { + mLanguage.setText(value); + } + } + } + + /** + * Edit widget for {@link RegionQualifier}. + */ + private class RegionEdit extends QualifierEditBase { + private Combo mRegion; + + public RegionEdit(Composite parent) { + super(parent, RegionQualifier.NAME); + + mRegion = new Combo(this, SWT.DROP_DOWN); + mRegion.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + mRegion.addVerifyListener(new LanguageRegionVerifier()); + mRegion.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + onRegionChange(); + } + public void widgetSelected(SelectionEvent e) { + onRegionChange(); + } + }); + mRegion.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + onRegionChange(); + } + }); + + new Label(this, SWT.NONE).setText("(2 letter code)"); + } + + private void onRegionChange() { + // update the current config + String value = mRegion.getText(); + + if (value.length() == 0) { + // empty string, means no qualifier. + // Since the qualifier classes are immutable, and we don't want to + // remove the qualifier from the configuration, we create a new default one. + mSelectedConfiguration.setRegionQualifier(new RegionQualifier()); + } else { + RegionQualifier qualifier = null; + String segment = RegionQualifier.getFolderSegment(value); + if (segment != null) { + qualifier = RegionQualifier.getQualifier(segment); + } + + if (qualifier != null) { + mSelectedConfiguration.setRegionQualifier(qualifier); + } else { + // Failure! Looks like the value is wrong (for instance a one letter string). + mSelectedConfiguration.setRegionQualifier(new RegionQualifier()); + } + } + + // notify of change + onChange(true /* keepSelection */); + } + + @Override + public void setQualifier(ResourceQualifier qualifier) { + RegionQualifier q = (RegionQualifier)qualifier; + + String value = q.getValue(); + if (value != null) { + mRegion.setText(q.getValue()); + } + } + } + + /** + * Edit widget for {@link ScreenOrientationQualifier}. + */ + private class OrientationEdit extends QualifierEditBase { + + private Combo mOrientation; + + public OrientationEdit(Composite parent) { + super(parent, ScreenOrientationQualifier.NAME); + + mOrientation = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY); + ScreenOrientation[] soValues = ScreenOrientation.values(); + for (ScreenOrientation value : soValues) { + mOrientation.add(value.getDisplayValue()); + } + + mOrientation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + mOrientation.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + onOrientationChange(); + } + public void widgetSelected(SelectionEvent e) { + onOrientationChange(); + } + }); + } + + protected void onOrientationChange() { + // update the current config + int index = mOrientation.getSelectionIndex(); + + if (index != -1) { + mSelectedConfiguration.setScreenOrientationQualifier(new ScreenOrientationQualifier( + ScreenOrientation.getByIndex(index))); + } else { + // empty selection, means no qualifier. + // Since the qualifier classes are immutable, and we don't want to + // remove the qualifier from the configuration, we create a new default one. + mSelectedConfiguration.setScreenOrientationQualifier( + new ScreenOrientationQualifier()); + } + + // notify of change + onChange(true /* keepSelection */); + } + + @Override + public void setQualifier(ResourceQualifier qualifier) { + ScreenOrientationQualifier q = (ScreenOrientationQualifier)qualifier; + + ScreenOrientation value = q.getValue(); + if (value == null) { + mOrientation.clearSelection(); + } else { + mOrientation.select(ScreenOrientation.getIndex(value)); + } + } + } + + /** + * Edit widget for {@link PixelDensityQualifier}. + */ + private class PixelDensityEdit extends QualifierEditBase { + private Text mText; + + public PixelDensityEdit(Composite parent) { + super(parent, PixelDensityQualifier.NAME); + + mText = new Text(this, SWT.BORDER); + mText.addVerifyListener(new DensityVerifier()); + mText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + onTextChange(); + } + }); + mText.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + onTextChange(); + } + }); + } + + private void onTextChange() { + String value = mText.getText(); + + if (value.length() == 0) { + // empty string, means a qualifier with no value. + // Since the qualifier classes are immutable, and we don't want to + // remove the qualifier from the configuration, we create a new default one. + mSelectedConfiguration.setPixelDensityQualifier(new PixelDensityQualifier()); + } else { + try { + PixelDensityQualifier qualifier = PixelDensityQualifier.getQualifier( + PixelDensityQualifier.getFolderSegment(Integer.parseInt(value))); + if (qualifier != null) { + mSelectedConfiguration.setPixelDensityQualifier(qualifier); + } else { + // Failure! Looks like the value is wrong + // (for instance a one letter string). + // We do nothing in this case. + return; + } + } catch (NumberFormatException nfe) { + // Looks like the code is not a number. This should not happen since the text + // field has a VerifyListener that prevents it. + // We do nothing in this case. + return; + } + } + + // notify of change + onChange(true /* keepSelection */); + } + + @Override + public void setQualifier(ResourceQualifier qualifier) { + PixelDensityQualifier q = (PixelDensityQualifier)qualifier; + + mText.setText(Integer.toString(q.getValue())); + } + } + + /** + * Edit widget for {@link TouchScreenQualifier}. + */ + private class TouchEdit extends QualifierEditBase { + + private Combo mTouchScreen; + + public TouchEdit(Composite parent) { + super(parent, TouchScreenQualifier.NAME); + + mTouchScreen = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY); + TouchScreenType[] tstValues = TouchScreenType.values(); + for (TouchScreenType value : tstValues) { + mTouchScreen.add(value.getDisplayValue()); + } + + mTouchScreen.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + mTouchScreen.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + onTouchChange(); + } + public void widgetSelected(SelectionEvent e) { + onTouchChange(); + } + }); + } + + protected void onTouchChange() { + // update the current config + int index = mTouchScreen.getSelectionIndex(); + + if (index != -1) { + mSelectedConfiguration.setTouchTypeQualifier(new TouchScreenQualifier( + TouchScreenType.getByIndex(index))); + } else { + // empty selection, means no qualifier. + // Since the qualifier classes are immutable, and we don't want to + // remove the qualifier from the configuration, we create a new default one. + mSelectedConfiguration.setTouchTypeQualifier(new TouchScreenQualifier()); + } + + // notify of change + onChange(true /* keepSelection */); + } + + @Override + public void setQualifier(ResourceQualifier qualifier) { + TouchScreenQualifier q = (TouchScreenQualifier)qualifier; + + TouchScreenType value = q.getValue(); + if (value == null) { + mTouchScreen.clearSelection(); + } else { + mTouchScreen.select(TouchScreenType.getIndex(value)); + } + } + } + + /** + * Edit widget for {@link KeyboardStateQualifier}. + */ + private class KeyboardEdit extends QualifierEditBase { + + private Combo mKeyboard; + + public KeyboardEdit(Composite parent) { + super(parent, KeyboardStateQualifier.NAME); + + mKeyboard = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY); + KeyboardState[] ksValues = KeyboardState.values(); + for (KeyboardState value : ksValues) { + mKeyboard.add(value.getDisplayValue()); + } + + mKeyboard.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + mKeyboard.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + onKeyboardChange(); + } + public void widgetSelected(SelectionEvent e) { + onKeyboardChange(); + } + }); + } + + protected void onKeyboardChange() { + // update the current config + int index = mKeyboard.getSelectionIndex(); + + if (index != -1) { + mSelectedConfiguration.setKeyboardStateQualifier(new KeyboardStateQualifier( + KeyboardState.getByIndex(index))); + } else { + // empty selection, means no qualifier. + // Since the qualifier classes are immutable, and we don't want to + // remove the qualifier from the configuration, we create a new default one. + mSelectedConfiguration.setKeyboardStateQualifier( + new KeyboardStateQualifier()); + } + + // notify of change + onChange(true /* keepSelection */); + } + + @Override + public void setQualifier(ResourceQualifier qualifier) { + KeyboardStateQualifier q = (KeyboardStateQualifier)qualifier; + + KeyboardState value = q.getValue(); + if (value == null) { + mKeyboard.clearSelection(); + } else { + mKeyboard.select(KeyboardState.getIndex(value)); + } + } + } + + /** + * Edit widget for {@link TextInputMethodQualifier}. + */ + private class TextInputEdit extends QualifierEditBase { + + private Combo mTextInput; + + public TextInputEdit(Composite parent) { + super(parent, TextInputMethodQualifier.NAME); + + mTextInput = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY); + TextInputMethod[] timValues = TextInputMethod.values(); + for (TextInputMethod value : timValues) { + mTextInput.add(value.getDisplayValue()); + } + + mTextInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + mTextInput.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + onTextInputChange(); + } + public void widgetSelected(SelectionEvent e) { + onTextInputChange(); + } + }); + } + + protected void onTextInputChange() { + // update the current config + int index = mTextInput.getSelectionIndex(); + + if (index != -1) { + mSelectedConfiguration.setTextInputMethodQualifier(new TextInputMethodQualifier( + TextInputMethod.getByIndex(index))); + } else { + // empty selection, means no qualifier. + // Since the qualifier classes are immutable, and we don't want to + // remove the qualifier from the configuration, we create a new default one. + mSelectedConfiguration.setTextInputMethodQualifier( + new TextInputMethodQualifier()); + } + + // notify of change + onChange(true /* keepSelection */); + } + + @Override + public void setQualifier(ResourceQualifier qualifier) { + TextInputMethodQualifier q = (TextInputMethodQualifier)qualifier; + + TextInputMethod value = q.getValue(); + if (value == null) { + mTextInput.clearSelection(); + } else { + mTextInput.select(TextInputMethod.getIndex(value)); + } + } + } + + /** + * Edit widget for {@link NavigationMethodQualifier}. + */ + private class NavigationEdit extends QualifierEditBase { + + private Combo mNavigation; + + public NavigationEdit(Composite parent) { + super(parent, NavigationMethodQualifier.NAME); + + mNavigation = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY); + NavigationMethod[] nmValues = NavigationMethod.values(); + for (NavigationMethod value : nmValues) { + mNavigation.add(value.getDisplayValue()); + } + + mNavigation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + mNavigation.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + onNavigationChange(); + } + public void widgetSelected(SelectionEvent e) { + onNavigationChange(); + } + }); + } + + protected void onNavigationChange() { + // update the current config + int index = mNavigation.getSelectionIndex(); + + if (index != -1) { + mSelectedConfiguration.setNavigationMethodQualifier(new NavigationMethodQualifier( + NavigationMethod.getByIndex(index))); + } else { + // empty selection, means no qualifier. + // Since the qualifier classes are immutable, and we don't want to + // remove the qualifier from the configuration, we create a new default one. + mSelectedConfiguration.setNavigationMethodQualifier( + new NavigationMethodQualifier()); + } + + // notify of change + onChange(true /* keepSelection */); + } + + @Override + public void setQualifier(ResourceQualifier qualifier) { + NavigationMethodQualifier q = (NavigationMethodQualifier)qualifier; + + NavigationMethod value = q.getValue(); + if (value == null) { + mNavigation.clearSelection(); + } else { + mNavigation.select(NavigationMethod.getIndex(value)); + } + } + } + + /** + * Edit widget for {@link ScreenDimensionQualifier}. + */ + private class ScreenDimensionEdit extends QualifierEditBase { + + private Text mSize1; + private Text mSize2; + + public ScreenDimensionEdit(Composite parent) { + super(parent, ScreenDimensionQualifier.NAME); + + ModifyListener modifyListener = new ModifyListener() { + public void modifyText(ModifyEvent e) { + onSizeChange(); + } + }; + + FocusAdapter focusListener = new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + onSizeChange(); + } + }; + + mSize1 = new Text(this, SWT.BORDER); + mSize1.addVerifyListener(new DimensionVerifier()); + mSize1.addModifyListener(modifyListener); + mSize1.addFocusListener(focusListener); + + mSize2 = new Text(this, SWT.BORDER); + mSize2.addVerifyListener(new DimensionVerifier()); + mSize2.addModifyListener(modifyListener); + mSize2.addFocusListener(focusListener); + } + + private void onSizeChange() { + // update the current config + String size1 = mSize1.getText(); + String size2 = mSize2.getText(); + + if (size1.length() == 0 || size2.length() == 0) { + // if one of the strings is empty, reset to no qualifier. + // Since the qualifier classes are immutable, and we don't want to + // remove the qualifier from the configuration, we create a new default one. + mSelectedConfiguration.setScreenDimensionQualifier(new ScreenDimensionQualifier()); + } else { + ScreenDimensionQualifier qualifier = ScreenDimensionQualifier.getQualifier(size1, + size2); + + if (qualifier != null) { + mSelectedConfiguration.setScreenDimensionQualifier(qualifier); + } else { + // Failure! Looks like the value is wrong, reset the qualifier + // Since the qualifier classes are immutable, and we don't want to + // remove the qualifier from the configuration, we create a new default one. + mSelectedConfiguration.setScreenDimensionQualifier( + new ScreenDimensionQualifier()); + } + } + + // notify of change + onChange(true /* keepSelection */); + } + + @Override + public void setQualifier(ResourceQualifier qualifier) { + ScreenDimensionQualifier q = (ScreenDimensionQualifier)qualifier; + + mSize1.setText(Integer.toString(q.getValue1())); + mSize2.setText(Integer.toString(q.getValue2())); + } + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/EclipseUiHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/EclipseUiHelper.java new file mode 100644 index 0000000..55878bf --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/EclipseUiHelper.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php + * + * 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.android.ide.eclipse.adt.ui; + +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; + +/** + * Helpers for Eclipse UI related stuff. + */ +public final class EclipseUiHelper { + + /** View Id for the default Eclipse Content Outline view. */ + public static final String CONTENT_OUTLINE_VIEW_ID = "org.eclipse.ui.views.ContentOutline"; + /** View Id for the default Eclipse Property Sheet view. */ + public static final String PROPERTY_SHEET_VIEW_ID = "org.eclipse.ui.views.PropertySheet"; + + /** This class never gets instantiated. */ + private EclipseUiHelper() { + } + + /** + * Shows the corresponding view. + *

+ * Silently fails in case of error. + * + * @param viewId One of {@link #CONTENT_OUTLINE_VIEW_ID}, {@link #PROPERTY_SHEET_VIEW_ID}. + * @param activate True to force activate (i.e. takes focus), false to just make visible (i.e. + * does not steal focus.) + */ + public static void showView(String viewId, boolean activate) { + IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (win != null) { + IWorkbenchPage page = win.getActivePage(); + if (page != null) { + try { + IViewPart part = page.showView(viewId, + null /* secondaryId */, + activate ? IWorkbenchPage.VIEW_ACTIVATE : IWorkbenchPage.VIEW_VISIBLE); + } catch (PartInitException e) { + // ignore + } + } + } + + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ReferenceChooserDialog.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ReferenceChooserDialog.java new file mode 100644 index 0000000..e141396 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ReferenceChooserDialog.java @@ -0,0 +1,266 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php + * + * 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.android.ide.eclipse.adt.ui; + +import com.android.ide.eclipse.adt.AdtPlugin; +import com.android.ide.eclipse.common.resources.IResourceRepository; +import com.android.ide.eclipse.common.resources.ResourceItem; +import com.android.ide.eclipse.common.resources.ResourceType; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.DialogSettings; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.TreePath; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.dialogs.FilteredTree; +import org.eclipse.ui.dialogs.PatternFilter; +import org.eclipse.ui.dialogs.SelectionStatusDialog; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * A dialog to let the user choose a reference to a resource. + * + */ +public class ReferenceChooserDialog extends SelectionStatusDialog { + + private static Pattern sResourcePattern = Pattern.compile("@(.*)/(.+)"); //$NON-NLS-1$ + private static Pattern sInlineIdResourcePattern = Pattern.compile("@\\+id/(.+)"); //$NON-NLS-1$ + + private static IDialogSettings sDialogSettings = new DialogSettings(""); + + private IResourceRepository mResources; + private String mCurrentResource; + + private FilteredTree mFilteredTree; + + /** + * @param parent + */ + public ReferenceChooserDialog(IResourceRepository resources, Shell parent) { + super(parent); + + int shellStyle = getShellStyle(); + setShellStyle(shellStyle | SWT.MAX | SWT.RESIZE); + + setTitle("Reference Dialog"); + setMessage(String.format("Choose a resource")); + mResources = resources; + + setDialogBoundsSettings(sDialogSettings, getDialogBoundsStrategy()); + } + + public void setCurrentResource(String resource) { + mCurrentResource = resource; + } + + public String getCurrentResource() { + return mCurrentResource; + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult() + */ + @Override + protected void computeResult() { + // get the selection + TreePath treeSelection = getSelection(); + if (treeSelection != null) { + if (treeSelection.getSegmentCount() == 2) { + // get the resource type and the resource item + ResourceType resourceType = (ResourceType)treeSelection.getFirstSegment(); + ResourceItem resourceItem = (ResourceItem)treeSelection.getLastSegment(); + + mCurrentResource = resourceType.getXmlString(resourceItem, false /* system */); + } + } + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite top = (Composite)super.createDialogArea(parent); + + // create the standard message area + createMessageArea(top); + + // create the filtered tree + createFilteredTree(top); + + // setup the initial selection + setupInitialSelection(); + + return top; + } + + private void createFilteredTree(Composite parent) { + mFilteredTree = new FilteredTree(parent, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION, + new PatternFilter()); + + GridData data = new GridData(); + data.widthHint = convertWidthInCharsToPixels(60); + data.heightHint = convertHeightInCharsToPixels(18); + data.grabExcessVerticalSpace = true; + data.grabExcessHorizontalSpace = true; + data.horizontalAlignment = GridData.FILL; + data.verticalAlignment = GridData.FILL; + mFilteredTree.setLayoutData(data); + mFilteredTree.setFont(parent.getFont()); + + TreeViewer treeViewer = mFilteredTree.getViewer(); + Tree tree = treeViewer.getTree(); + + tree.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + handleDoubleClick(); + } + + public void widgetSelected(SelectionEvent e) { + handleSelection(); + } + }); + + treeViewer.setLabelProvider(new ResourceLabelProvider()); + treeViewer.setContentProvider(new ResourceContentProvider(false /* fullLevels */)); + treeViewer.setInput(mResources); + } + + protected void handleSelection() { + validateCurrentSelection(); + } + + protected void handleDoubleClick() { + if (validateCurrentSelection()) { + buttonPressed(IDialogConstants.OK_ID); + } + } + + /** + * Returns the selected item in the tree as a {@link TreePath} object. + * @return the TreePath object or null if there was no selection. + */ + private TreePath getSelection() { + ISelection selection = mFilteredTree.getViewer().getSelection(); + if (selection instanceof TreeSelection) { + TreeSelection treeSelection = (TreeSelection)selection; + TreePath[] treePaths = treeSelection.getPaths(); + + // the selection mode is SWT.SINGLE, so we just get the first one. + if (treePaths.length > 0) { + return treePaths[0]; + } + } + + return null; + } + + private boolean validateCurrentSelection() { + TreePath treeSelection = getSelection(); + + IStatus status; + if (treeSelection != null) { + if (treeSelection.getSegmentCount() == 2) { + status = new Status(IStatus.OK, AdtPlugin.PLUGIN_ID, + IStatus.OK, "", //$NON-NLS-1$ + null); + } else { + status = new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, + IStatus.ERROR, "You must select a Resource Item", + null); + } + } else { + status = new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, + IStatus.ERROR, "", //$NON-NLS-1$ + null); + } + + updateStatus(status); + + return status.isOK(); + } + + /** + * Sets up the initial selection. + *

+ * This parses {@link #mCurrentResource} to find out the resource type and the resource name. + */ + private void setupInitialSelection() { + // checks the inline id pattern first as it's more restrictive than the other one. + Matcher m = sInlineIdResourcePattern.matcher(mCurrentResource); + if (m.matches()) { + // get the matching name + String resourceName = m.group(1); + + // setup initial selection + setupInitialSelection(ResourceType.ID, resourceName); + } else { + // attempts the inline id pattern + m = sResourcePattern.matcher(mCurrentResource); + if (m.matches()) { + // get the resource type. + ResourceType resourceType = ResourceType.getEnum(m.group(1)); + if (resourceType != null) { + // get the matching name + String resourceName = m.group(2); + + // setup initial selection + setupInitialSelection(resourceType, resourceName); + } + } + } + } + + /** + * Sets up the initial selection based on a {@link ResourceType} and a resource name. + * @param resourceType the resource type. + * @param resourceName the resource name. + */ + private void setupInitialSelection(ResourceType resourceType, String resourceName) { + // get all the resources of this type + ResourceItem[] resourceItems = mResources.getResources(resourceType); + + for (ResourceItem resourceItem : resourceItems) { + if (resourceName.equals(resourceItem.getName())) { + // name of the resource match, we select it, + TreePath treePath = new TreePath(new Object[] { resourceType, resourceItem }); + mFilteredTree.getViewer().setSelection(new TreeSelection(treePath)); + + // and we're done. + return; + } + } + + // if we get here, the resource type is valid, but the resource is missing. + // we select and expand the resource type element. + TreePath treePath = new TreePath(new Object[] { resourceType }); + mFilteredTree.getViewer().setSelection(new TreeSelection(treePath)); + mFilteredTree.getViewer().setExpandedState(resourceType, true /* expanded */); + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ResourceChooser.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ResourceChooser.java new file mode 100644 index 0000000..4290f6b --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ResourceChooser.java @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php + * + * 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.android.ide.eclipse.adt.ui; + +import com.android.ide.eclipse.common.resources.IResourceRepository; +import com.android.ide.eclipse.common.resources.ResourceItem; +import com.android.ide.eclipse.common.resources.ResourceType; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.AbstractElementListSelectionDialog; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * A dialog to let the user select a resource based on a resource type. + */ +public class ResourceChooser extends AbstractElementListSelectionDialog { + + private Pattern mProjectResourcePattern; + + private ResourceType mResourceType; + + private IResourceRepository mProjectResources; + + // TODO: enable when we can display the system resources. + // private Pattern mSystemResourcePattern; + // private IResourceRepository mSystemResources; + // private Button mProjectButton; + // private Button mSystemButton; + + private String mCurrentResource; + + /** + * Creates a Resource Chooser dialog. + * @param type The type of the resource to choose + * @param project The repository for the project + * @param system The System resource repository + * @param parent the parent shell + */ + public ResourceChooser(ResourceType type, IResourceRepository project, + IResourceRepository system, Shell parent) { + super(parent, new ResourceLabelProvider()); + + mResourceType = type; + mProjectResources = project; + // TODO: enable when we can display the system resources. + // mSystemResources = system; + + mProjectResourcePattern = Pattern.compile( + "@" + mResourceType.getName() + "/(.+)"); //$NON-NLS-1$ //$NON-NLS-2$ + // TODO: enable when we can display the system resources. + // mSystemResourcePattern = Pattern.compile( + // "@android:" + mResourceType.getName() + "/(.+)"); //$NON-NLS-1$ //$NON-NLS-2$ + + setTitle("Resource Chooser"); + setMessage(String.format("Choose a %1$s resource", + mResourceType.getDisplayName().toLowerCase())); + } + + public void setCurrentResource(String resource) { + mCurrentResource = resource; + } + + public String getCurrentResource() { + return mCurrentResource; + } + + @Override + protected void computeResult() { + Object[] elements = getSelectedElements(); + if (elements.length == 1 && elements[0] instanceof ResourceItem) { + ResourceItem item = (ResourceItem)elements[0]; + + mCurrentResource = mResourceType.getXmlString(item, + // TODO: enable when we can display the system resources. + false /*mSystemButton.getSelection()*/); + } + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite top = (Composite)super.createDialogArea(parent); + + createMessageArea(top); + + // TODO: enable when we can display the system resources. + // createButtons(top); + + createFilterText(top); + createFilteredList(top); + + setupResourceListAndCurrent(); + + return top; + } + + /** + * Creates the radio button to switch between project and system resources. + * @param top the parent composite + */ + /* TODO: enable when we can display the system resources. + private void createButtons(Composite top) { + mProjectButton = new Button(top, SWT.RADIO); + mProjectButton.setText("Project Resources"); + mProjectButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + super.widgetSelected(e); + setListElements(mProjectResources.getResources(mResourceType)); + } + }); + mSystemButton = new Button(top, SWT.RADIO); + mSystemButton.setText("System Resources"); + mSystemButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + super.widgetSelected(e); + setListElements(mSystemResources.getResources(mResourceType)); + } + }); + } + */ + + /** + * Setups the current list based on the current resource. + */ + private void setupResourceListAndCurrent() { + if (setupInitialSelection(mProjectResourcePattern, mProjectResources) == false) { + // if we couldn't understand the current value, we default to the project resources + ResourceItem[] items = mProjectResources.getResources(mResourceType); + setListElements(items); + } + /* + * TODO: enable when we can display the system resources. + if (setupInitialSelection(mProjectResourcePattern, mProjectResources) == false) { + if (setupInitialSelection(mSystemResourcePattern, mSystemResources) == false) { + // if we couldn't understand the current value, we default to the project resources + IResourceItem[] items = mProjectResources.getResources(mResourceType); + setListElements(items); + mProjectButton.setSelection(true); + } else { + mSystemButton.setSelection(true); + } + } else { + mProjectButton.setSelection(true); + }*/ + } + + /** + * Attempts to setup the list of element from a repository if the current resource + * matches the provided pattern. + * @param pattern the pattern to test the current value + * @param repository the repository to use if the pattern matches. + * @return true if success. + */ + private boolean setupInitialSelection(Pattern pattern, IResourceRepository repository) { + Matcher m = pattern.matcher(mCurrentResource); + if (m.matches()) { + // we have a project resource, let's setup the list + ResourceItem[] items = repository.getResources(mResourceType); + setListElements(items); + + // and let's look for the item we found + String name = m.group(1); + + for (ResourceItem item : items) { + if (name.equals(item.getName())) { + setSelection(new Object[] { item }); + break; + } + } + return true; + } + return false; + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ResourceContentProvider.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ResourceContentProvider.java new file mode 100644 index 0000000..3792fe3 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ResourceContentProvider.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php + * + * 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.android.ide.eclipse.adt.ui; + +import com.android.ide.eclipse.common.resources.IResourceRepository; +import com.android.ide.eclipse.common.resources.ResourceItem; +import com.android.ide.eclipse.common.resources.ResourceType; +import com.android.ide.eclipse.editors.resources.manager.ConfigurableResourceItem; +import com.android.ide.eclipse.editors.resources.manager.ResourceFile; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** + * Content provider for the Resource Explorer TreeView. + * Each level of the tree is represented by a different class. + *

    + *
  • {@link ResourceType}. This represents the list of existing Resource Type present + * in the resources. This can be matched to the subclasses inside the class R + *
  • + *
      + *
    • {@link ResourceItem}. This represents one resource (which can existing in various alternate + * versions). This is similar to the resource Ids defined as R.sometype.id. + *
    • + *
        + *
      • {@link ResourceFile}. (optional) This represents a particular version of the + * {@link ResourceItem}. It is displayed as a list of resource qualifier. + *
      • + *
      + *
    + *
+ * + * @see ResourceLabelProvider + */ +public class ResourceContentProvider implements ITreeContentProvider { + + /** + * The current ProjectResources being displayed. + */ + private IResourceRepository mResources; + + private boolean mFullLevels; + + /** + * Constructs a new content providers for resource display. + * @param fullLevels if true the content provider will suppport all 3 levels. If + * false, only two levels are provided. + */ + public ResourceContentProvider(boolean fullLevels) { + mFullLevels = fullLevels; + } + + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof ResourceType) { + return mResources.getResources((ResourceType)parentElement); + } else if (mFullLevels && parentElement instanceof ConfigurableResourceItem) { + return ((ConfigurableResourceItem)parentElement).getSourceFileArray(); + } + return null; + } + + public Object getParent(Object element) { + // pass + return null; + } + + public boolean hasChildren(Object element) { + if (element instanceof ResourceType) { + return mResources.hasResources((ResourceType)element); + } else if (mFullLevels && element instanceof ConfigurableResourceItem) { + return ((ConfigurableResourceItem)element).hasAlternates(); + } + return false; + } + + public Object[] getElements(Object inputElement) { + if (inputElement instanceof IResourceRepository) { + if ((IResourceRepository)inputElement == mResources) { + // get the top level resources. + return mResources.getAvailableResourceTypes(); + } + } + + return new Object[0]; + } + + public void dispose() { + // pass + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + if (newInput instanceof IResourceRepository) { + mResources = (IResourceRepository)newInput; + } + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ResourceLabelProvider.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ResourceLabelProvider.java new file mode 100644 index 0000000..f7c2634 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ui/ResourceLabelProvider.java @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php + * + * 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.android.ide.eclipse.adt.ui; + +import com.android.ide.eclipse.common.resources.IIdResourceItem; +import com.android.ide.eclipse.common.resources.ResourceItem; +import com.android.ide.eclipse.common.resources.ResourceType; +import com.android.ide.eclipse.editors.resources.manager.ConfigurableResourceItem; +import com.android.ide.eclipse.editors.resources.manager.IdResourceItem; +import com.android.ide.eclipse.editors.resources.manager.ResourceFile; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; + +/** + * Label provider for the Resource Explorer TreeView. + * Each level of the tree is represented by a different class. + *
    + *
  • {@link ResourceType}. This represents the list of existing Resource Type present + * in the resources. This can be matched to the subclasses inside the class R + *
  • + *
      + *
    • {@link ResourceItem}. This represents one resource. The actual type can be + * {@link ConfigurableResourceItem} (which can exist in various alternate versions), + * or {@link IdResourceItem}. + * This is similar to the resource Ids defined as R.sometype.id. + *
    • + *
        + *
      • {@link ResourceFile}. This represents a particular version of the {@link ResourceItem}. + * It is displayed as a list of resource qualifier. + *
      • + *
      + *
    + *
+ * + * @see ResourceContentProvider + */ +public class ResourceLabelProvider implements ILabelProvider, ITableLabelProvider { + private Image mWarningImage; + + public ResourceLabelProvider() { + mWarningImage = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( + ISharedImages.IMG_OBJS_WARN_TSK).createImage(); + } + + /** + * @see #getColumnImage(Object, int) + */ + public Image getImage(Object element) { + // pass + return null; + } + + /** + * @see #getColumnText(Object, int) + */ + public String getText(Object element) { + return getColumnText(element, 0); + } + + public void addListener(ILabelProviderListener listener) { + // pass + } + + public void dispose() { + mWarningImage.dispose(); + } + + public boolean isLabelProperty(Object element, String property) { + return false; + } + + public void removeListener(ILabelProviderListener listener) { + // pass + } + + public Image getColumnImage(Object element, int columnIndex) { + if (columnIndex == 1) { + if (element instanceof ConfigurableResourceItem) { + ConfigurableResourceItem item = (ConfigurableResourceItem)element; + if (item.hasDefault() == false) { + return mWarningImage; + } + } + } + return null; + } + + public String getColumnText(Object element, int columnIndex) { + switch (columnIndex) { + case 0: + if (element instanceof ResourceType) { + return ((ResourceType)element).getDisplayName(); + } else if (element instanceof ResourceItem) { + return ((ResourceItem)element).getName(); + } else if (element instanceof ResourceFile) { + return ((ResourceFile)element).getFolder().getConfiguration().toDisplayString(); + } + break; + case 1: + if (element instanceof ConfigurableResourceItem) { + ConfigurableResourceItem item = (ConfigurableResourceItem)element; + int count = item.getAlternateCount(); + if (count > 0) { + if (item.hasDefault()) { + count++; + } + return String.format("%1$d version(s)", count); + } + } else if (element instanceof IIdResourceItem) { + IIdResourceItem idResource = (IIdResourceItem)element; + if (idResource.isDeclaredInline()) { + return "Declared inline"; + } + } + return null; + } + return null; + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/wizards/newxmlfile/NewXmlFileCreationPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/wizards/newxmlfile/NewXmlFileCreationPage.java index f3cbfa2..f850504 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/wizards/newxmlfile/NewXmlFileCreationPage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/wizards/newxmlfile/NewXmlFileCreationPage.java @@ -21,6 +21,8 @@ import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.sdk.AndroidTargetData; import com.android.ide.eclipse.adt.sdk.Sdk; import com.android.ide.eclipse.adt.sdk.Sdk.ITargetChangeListener; +import com.android.ide.eclipse.adt.ui.ConfigurationSelector; +import com.android.ide.eclipse.adt.ui.ConfigurationSelector.ConfigurationState; import com.android.ide.eclipse.common.AndroidConstants; import com.android.ide.eclipse.common.project.ProjectChooserHelper; import com.android.ide.eclipse.editors.descriptors.DocumentDescriptor; @@ -31,8 +33,6 @@ import com.android.ide.eclipse.editors.resources.configurations.FolderConfigurat import com.android.ide.eclipse.editors.resources.configurations.ResourceQualifier; import com.android.ide.eclipse.editors.resources.descriptors.ResourcesDescriptors; import com.android.ide.eclipse.editors.resources.manager.ResourceFolderType; -import com.android.ide.eclipse.editors.wizards.ConfigurationSelector; -import com.android.ide.eclipse.editors.wizards.ConfigurationSelector.ConfigurationState; import com.android.sdklib.IAndroidTarget; import com.android.sdklib.SdkConstants; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/EclipseUiHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/EclipseUiHelper.java deleted file mode 100644 index 6dc8562..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/EclipseUiHelper.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.common; - -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; - -/** - * Helpers for Eclipse UI related stuff. - */ -public final class EclipseUiHelper { - - /** View Id for the default Eclipse Content Outline view. */ - public static final String CONTENT_OUTLINE_VIEW_ID = "org.eclipse.ui.views.ContentOutline"; - /** View Id for the default Eclipse Property Sheet view. */ - public static final String PROPERTY_SHEET_VIEW_ID = "org.eclipse.ui.views.PropertySheet"; - - /** This class never gets instantiated. */ - private EclipseUiHelper() { - } - - /** - * Shows the corresponding view. - *

- * Silently fails in case of error. - * - * @param viewId One of {@link #CONTENT_OUTLINE_VIEW_ID}, {@link #PROPERTY_SHEET_VIEW_ID}. - * @param activate True to force activate (i.e. takes focus), false to just make visible (i.e. - * does not steal focus.) - */ - public static void showView(String viewId, boolean activate) { - IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (win != null) { - IWorkbenchPage page = win.getActivePage(); - if (page != null) { - try { - IViewPart part = page.showView(viewId, - null /* secondaryId */, - activate ? IWorkbenchPage.VIEW_ACTIVATE : IWorkbenchPage.VIEW_VISIBLE); - } catch (PartInitException e) { - // ignore - } - } - } - - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/GraphicalLayoutEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/GraphicalLayoutEditor.java index 12d49fe..e223820 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/GraphicalLayoutEditor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/GraphicalLayoutEditor.java @@ -22,6 +22,10 @@ import com.android.ide.eclipse.adt.sdk.LoadStatus; import com.android.ide.eclipse.adt.sdk.Sdk; import com.android.ide.eclipse.adt.sdk.AndroidTargetData.LayoutBridge; import com.android.ide.eclipse.adt.sdk.Sdk.ITargetChangeListener; +import com.android.ide.eclipse.adt.ui.ConfigurationSelector.DensityVerifier; +import com.android.ide.eclipse.adt.ui.ConfigurationSelector.DimensionVerifier; +import com.android.ide.eclipse.adt.ui.ConfigurationSelector.LanguageRegionVerifier; +import com.android.ide.eclipse.adt.ui.ConfigurationSelector.MobileCodeVerifier; import com.android.ide.eclipse.common.resources.ResourceType; import com.android.ide.eclipse.editors.IconFactory; import com.android.ide.eclipse.editors.layout.LayoutEditor.UiEditorActions; @@ -55,10 +59,6 @@ import com.android.ide.eclipse.editors.ui.tree.CopyCutAction; import com.android.ide.eclipse.editors.ui.tree.PasteAction; import com.android.ide.eclipse.editors.uimodel.UiDocumentNode; import com.android.ide.eclipse.editors.uimodel.UiElementNode; -import com.android.ide.eclipse.editors.wizards.ConfigurationSelector.DensityVerifier; -import com.android.ide.eclipse.editors.wizards.ConfigurationSelector.DimensionVerifier; -import com.android.ide.eclipse.editors.wizards.ConfigurationSelector.LanguageRegionVerifier; -import com.android.ide.eclipse.editors.wizards.ConfigurationSelector.MobileCodeVerifier; import com.android.layoutlib.api.ILayoutLog; import com.android.layoutlib.api.ILayoutResult; import com.android.layoutlib.api.IProjectCallback; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/LayoutCreatorDialog.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/LayoutCreatorDialog.java index c4a8f5c..6940238 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/LayoutCreatorDialog.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/LayoutCreatorDialog.java @@ -16,12 +16,12 @@ package com.android.ide.eclipse.editors.layout; +import com.android.ide.eclipse.adt.ui.ConfigurationSelector; +import com.android.ide.eclipse.adt.ui.ConfigurationSelector.ConfigurationState; import com.android.ide.eclipse.editors.IconFactory; import com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration; import com.android.ide.eclipse.editors.resources.configurations.ResourceQualifier; import com.android.ide.eclipse.editors.resources.manager.ResourceFolderType; -import com.android.ide.eclipse.editors.wizards.ConfigurationSelector; -import com.android.ide.eclipse.editors.wizards.ConfigurationSelector.ConfigurationState; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.TrayDialog; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/LayoutEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/LayoutEditor.java index f3a5113..7bed7ce 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/LayoutEditor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/LayoutEditor.java @@ -18,8 +18,8 @@ package com.android.ide.eclipse.editors.layout; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.sdk.AndroidTargetData; +import com.android.ide.eclipse.adt.ui.EclipseUiHelper; import com.android.ide.eclipse.common.AndroidConstants; -import com.android.ide.eclipse.common.EclipseUiHelper; import com.android.ide.eclipse.editors.AndroidEditor; import com.android.ide.eclipse.editors.descriptors.DocumentDescriptor; import com.android.ide.eclipse.editors.resources.manager.ResourceFolder; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/UiContentOutlinePage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/UiContentOutlinePage.java index 536e902..4e0e35f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/UiContentOutlinePage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/layout/UiContentOutlinePage.java @@ -17,7 +17,7 @@ package com.android.ide.eclipse.editors.layout; -import com.android.ide.eclipse.common.EclipseUiHelper; +import com.android.ide.eclipse.adt.ui.EclipseUiHelper; import com.android.ide.eclipse.editors.IconFactory; import com.android.ide.eclipse.editors.layout.parts.UiDocumentTreeEditPart; import com.android.ide.eclipse.editors.layout.parts.UiElementTreeEditPart; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/resources/explorer/ResourceExplorerView.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/resources/explorer/ResourceExplorerView.java index d1d8891..b61eddc 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/resources/explorer/ResourceExplorerView.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/resources/explorer/ResourceExplorerView.java @@ -17,14 +17,14 @@ package com.android.ide.eclipse.editors.resources.explorer; import com.android.ide.eclipse.adt.AdtPlugin; +import com.android.ide.eclipse.adt.ui.ResourceContentProvider; +import com.android.ide.eclipse.adt.ui.ResourceLabelProvider; import com.android.ide.eclipse.common.AndroidConstants; import com.android.ide.eclipse.editors.resources.manager.ProjectResourceItem; import com.android.ide.eclipse.editors.resources.manager.ProjectResources; import com.android.ide.eclipse.editors.resources.manager.ResourceFile; import com.android.ide.eclipse.editors.resources.manager.ResourceManager; import com.android.ide.eclipse.editors.resources.manager.ResourceMonitor.IResourceEventListener; -import com.android.ide.eclipse.editors.wizards.ResourceContentProvider; -import com.android.ide.eclipse.editors.wizards.ResourceLabelProvider; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/uimodel/UiResourceAttributeNode.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/uimodel/UiResourceAttributeNode.java index 32cac9f..654e792 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/uimodel/UiResourceAttributeNode.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/uimodel/UiResourceAttributeNode.java @@ -17,6 +17,8 @@ package com.android.ide.eclipse.editors.uimodel; import com.android.ide.eclipse.adt.sdk.AndroidTargetData; +import com.android.ide.eclipse.adt.ui.ReferenceChooserDialog; +import com.android.ide.eclipse.adt.ui.ResourceChooser; import com.android.ide.eclipse.common.resources.IResourceRepository; import com.android.ide.eclipse.common.resources.ResourceItem; import com.android.ide.eclipse.common.resources.ResourceType; @@ -26,8 +28,6 @@ import com.android.ide.eclipse.editors.descriptors.DescriptorsUtils; import com.android.ide.eclipse.editors.descriptors.TextAttributeDescriptor; import com.android.ide.eclipse.editors.resources.manager.ResourceManager; import com.android.ide.eclipse.editors.ui.SectionHelper; -import com.android.ide.eclipse.editors.wizards.ReferenceChooserDialog; -import com.android.ide.eclipse.editors.wizards.ResourceChooser; import org.eclipse.core.resources.IProject; import org.eclipse.jface.window.Window; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ConfigurationSelector.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ConfigurationSelector.java deleted file mode 100644 index 4a05b1e..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ConfigurationSelector.java +++ /dev/null @@ -1,1278 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.editors.wizards; - -import com.android.ide.eclipse.editors.resources.configurations.CountryCodeQualifier; -import com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration; -import com.android.ide.eclipse.editors.resources.configurations.KeyboardStateQualifier; -import com.android.ide.eclipse.editors.resources.configurations.LanguageQualifier; -import com.android.ide.eclipse.editors.resources.configurations.NavigationMethodQualifier; -import com.android.ide.eclipse.editors.resources.configurations.NetworkCodeQualifier; -import com.android.ide.eclipse.editors.resources.configurations.PixelDensityQualifier; -import com.android.ide.eclipse.editors.resources.configurations.RegionQualifier; -import com.android.ide.eclipse.editors.resources.configurations.ResourceQualifier; -import com.android.ide.eclipse.editors.resources.configurations.ScreenDimensionQualifier; -import com.android.ide.eclipse.editors.resources.configurations.ScreenOrientationQualifier; -import com.android.ide.eclipse.editors.resources.configurations.TextInputMethodQualifier; -import com.android.ide.eclipse.editors.resources.configurations.TouchScreenQualifier; -import com.android.ide.eclipse.editors.resources.configurations.KeyboardStateQualifier.KeyboardState; -import com.android.ide.eclipse.editors.resources.configurations.NavigationMethodQualifier.NavigationMethod; -import com.android.ide.eclipse.editors.resources.configurations.ScreenOrientationQualifier.ScreenOrientation; -import com.android.ide.eclipse.editors.resources.configurations.TextInputMethodQualifier.TextInputMethod; -import com.android.ide.eclipse.editors.resources.configurations.TouchScreenQualifier.TouchScreenType; -import com.android.ide.eclipse.editors.resources.manager.ResourceManager; - -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StackLayout; -import org.eclipse.swt.events.ControlAdapter; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.events.VerifyEvent; -import org.eclipse.swt.events.VerifyListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.Text; - -import java.util.HashMap; - -/** - * Custom UI widget to let user build a Folder configuration. - *

- * To use this, instantiate somewhere in the UI and then: - *

    - *
  • Use {@link #setConfiguration(String)} or {@link #setConfiguration(FolderConfiguration)}. - *
  • Retrieve the configuration using {@link #getConfiguration(FolderConfiguration)}. - *
- */ -public class ConfigurationSelector extends Composite { - - public static final int WIDTH_HINT = 600; - public static final int HEIGHT_HINT = 250; - - private Runnable mOnChangeListener; - - private TableViewer mFullTableViewer; - private TableViewer mSelectionTableViewer; - private Button mAddButton; - private Button mRemoveButton; - private StackLayout mStackLayout; - - private boolean mOnRefresh = false; - - private final FolderConfiguration mBaseConfiguration = new FolderConfiguration(); - private final FolderConfiguration mSelectedConfiguration = new FolderConfiguration(); - - private final HashMap, QualifierEditBase> mUiMap = - new HashMap, QualifierEditBase>(); - private Composite mQualifierEditParent; - - /** - * Basic of {@link VerifyListener} to only accept digits. - */ - private static class DigitVerifier implements VerifyListener { - public void verifyText(VerifyEvent e) { - // check for digit only. - for (int i = 0 ; i < e.text.length(); i++) { - char letter = e.text.charAt(i); - if (letter < '0' || letter > '9') { - e.doit = false; - return; - } - } - } - } - - /** - * Implementation of {@link VerifyListener} for Country Code qualifiers. - */ - public static class MobileCodeVerifier extends DigitVerifier { - @Override - public void verifyText(VerifyEvent e) { - super.verifyText(e); - - // basic tests passed? - if (e.doit) { - // check the max 3 digits. - if (e.text.length() - e.end + e.start + - ((Text)e.getSource()).getText().length() > 3) { - e.doit = false; - } - } - } - } - - /** - * Implementation of {@link VerifyListener} for the Language and Region qualifiers. - */ - public static class LanguageRegionVerifier implements VerifyListener { - public void verifyText(VerifyEvent e) { - // check for length - if (e.text.length() - e.end + e.start + ((Combo)e.getSource()).getText().length() > 2) { - e.doit = false; - return; - } - - // check for lower case only. - for (int i = 0 ; i < e.text.length(); i++) { - char letter = e.text.charAt(i); - if ((letter < 'a' || letter > 'z') && (letter < 'A' || letter > 'Z')) { - e.doit = false; - return; - } - } - } - } - - /** - * Implementation of {@link VerifyListener} for the Pixel Density qualifier. - */ - public static class DensityVerifier extends DigitVerifier { } - - /** - * Implementation of {@link VerifyListener} for the Screen Dimension qualifier. - */ - public static class DimensionVerifier extends DigitVerifier { } - - /** - * Enum for the state of the configuration being created. - */ - public enum ConfigurationState { - OK, INVALID_CONFIG, REGION_WITHOUT_LANGUAGE; - } - - public ConfigurationSelector(Composite parent) { - super(parent, SWT.NONE); - - mBaseConfiguration.createDefault(); - - GridLayout gl = new GridLayout(4, false); - gl.marginWidth = gl.marginHeight = 0; - setLayout(gl); - - // first column is the first table - final Table fullTable = new Table(this, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER); - fullTable.setLayoutData(new GridData(GridData.FILL_BOTH)); - fullTable.setHeaderVisible(true); - fullTable.setLinesVisible(true); - - // create the column - final TableColumn fullTableColumn = new TableColumn(fullTable, SWT.LEFT); - // set the header - fullTableColumn.setText("Available Qualifiers"); - - fullTable.addControlListener(new ControlAdapter() { - @Override - public void controlResized(ControlEvent e) { - Rectangle r = fullTable.getClientArea(); - fullTableColumn.setWidth(r.width); - } - }); - - mFullTableViewer = new TableViewer(fullTable); - mFullTableViewer.setContentProvider(new QualifierContentProvider()); - mFullTableViewer.setLabelProvider(new QualifierLabelProvider( - false /* showQualifierValue */)); - mFullTableViewer.setInput(mBaseConfiguration); - mFullTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - ISelection selection = event.getSelection(); - if (selection instanceof IStructuredSelection) { - IStructuredSelection structSelection = (IStructuredSelection)selection; - Object first = structSelection.getFirstElement(); - - if (first instanceof ResourceQualifier) { - mAddButton.setEnabled(true); - return; - } - } - - mAddButton.setEnabled(false); - } - }); - - // 2nd column is the left/right arrow button - Composite buttonComposite = new Composite(this, SWT.NONE); - gl = new GridLayout(1, false); - gl.marginWidth = gl.marginHeight = 0; - buttonComposite.setLayout(gl); - buttonComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); - - new Composite(buttonComposite, SWT.NONE); - mAddButton = new Button(buttonComposite, SWT.BORDER | SWT.PUSH); - mAddButton.setText("->"); - mAddButton.setEnabled(false); - mAddButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - IStructuredSelection selection = - (IStructuredSelection)mFullTableViewer.getSelection(); - - Object first = selection.getFirstElement(); - if (first instanceof ResourceQualifier) { - ResourceQualifier qualifier = (ResourceQualifier)first; - - mBaseConfiguration.removeQualifier(qualifier); - mSelectedConfiguration.addQualifier(qualifier); - - mFullTableViewer.refresh(); - mSelectionTableViewer.refresh(); - mSelectionTableViewer.setSelection(new StructuredSelection(qualifier), true); - - onChange(false /* keepSelection */); - } - } - }); - - mRemoveButton = new Button(buttonComposite, SWT.BORDER | SWT.PUSH); - mRemoveButton.setText("<-"); - mRemoveButton.setEnabled(false); - mRemoveButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - IStructuredSelection selection = - (IStructuredSelection)mSelectionTableViewer.getSelection(); - - Object first = selection.getFirstElement(); - if (first instanceof ResourceQualifier) { - ResourceQualifier qualifier = (ResourceQualifier)first; - - mSelectedConfiguration.removeQualifier(qualifier); - mBaseConfiguration.addQualifier(qualifier); - - mFullTableViewer.refresh(); - mSelectionTableViewer.refresh(); - - onChange(false /* keepSelection */); - } - } - }); - - // 3rd column is the selected config table - final Table selectionTable = new Table(this, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER); - selectionTable.setLayoutData(new GridData(GridData.FILL_BOTH)); - selectionTable.setHeaderVisible(true); - selectionTable.setLinesVisible(true); - - // create the column - final TableColumn selectionTableColumn = new TableColumn(selectionTable, SWT.LEFT); - // set the header - selectionTableColumn.setText("Chosen Qualifiers"); - - selectionTable.addControlListener(new ControlAdapter() { - @Override - public void controlResized(ControlEvent e) { - Rectangle r = selectionTable.getClientArea(); - selectionTableColumn.setWidth(r.width); - } - }); - mSelectionTableViewer = new TableViewer(selectionTable); - mSelectionTableViewer.setContentProvider(new QualifierContentProvider()); - mSelectionTableViewer.setLabelProvider(new QualifierLabelProvider( - true /* showQualifierValue */)); - mSelectionTableViewer.setInput(mSelectedConfiguration); - mSelectionTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - // ignore selection changes during resfreshes in some cases. - if (mOnRefresh) { - return; - } - - ISelection selection = event.getSelection(); - if (selection instanceof IStructuredSelection) { - IStructuredSelection structSelection = (IStructuredSelection)selection; - - if (structSelection.isEmpty() == false) { - Object first = structSelection.getFirstElement(); - - if (first instanceof ResourceQualifier) { - mRemoveButton.setEnabled(true); - - QualifierEditBase composite = mUiMap.get(first.getClass()); - - if (composite != null) { - composite.setQualifier((ResourceQualifier)first); - } - - mStackLayout.topControl = composite; - mQualifierEditParent.layout(); - - return; - } - } else { - mStackLayout.topControl = null; - mQualifierEditParent.layout(); - } - } - - mRemoveButton.setEnabled(false); - } - }); - - // 4th column is the detail of the selected qualifier - mQualifierEditParent = new Composite(this, SWT.NONE); - mQualifierEditParent.setLayout(mStackLayout = new StackLayout()); - mQualifierEditParent.setLayoutData(new GridData(GridData.FILL_VERTICAL)); - - // create the UI for all the qualifiers, and associate them to the ResourceQualifer class. - mUiMap.put(CountryCodeQualifier.class, new MCCEdit(mQualifierEditParent)); - mUiMap.put(NetworkCodeQualifier.class, new MNCEdit(mQualifierEditParent)); - mUiMap.put(LanguageQualifier.class, new LanguageEdit(mQualifierEditParent)); - mUiMap.put(RegionQualifier.class, new RegionEdit(mQualifierEditParent)); - mUiMap.put(ScreenOrientationQualifier.class, new OrientationEdit(mQualifierEditParent)); - mUiMap.put(PixelDensityQualifier.class, new PixelDensityEdit(mQualifierEditParent)); - mUiMap.put(TouchScreenQualifier.class, new TouchEdit(mQualifierEditParent)); - mUiMap.put(KeyboardStateQualifier.class, new KeyboardEdit(mQualifierEditParent)); - mUiMap.put(TextInputMethodQualifier.class, new TextInputEdit(mQualifierEditParent)); - mUiMap.put(NavigationMethodQualifier.class, new NavigationEdit(mQualifierEditParent)); - mUiMap.put(ScreenDimensionQualifier.class, new ScreenDimensionEdit(mQualifierEditParent)); - } - - /** - * Sets a listener to be notified when the configuration changes. - * @param listener A {@link Runnable} whose run() method is called when the - * configuration is changed. The method is called from the UI thread. - */ - public void setOnChangeListener(Runnable listener) { - mOnChangeListener = listener; - } - - /** - * Initialize the UI with a given {@link FolderConfiguration}. This must - * be called from the UI thread. - * @param config The configuration. - */ - public void setConfiguration(FolderConfiguration config) { - mSelectedConfiguration.set(config); - mSelectionTableViewer.refresh(); - - // create the base config, which is the default config minus the qualifiers - // in SelectedConfiguration - mBaseConfiguration.substract(mSelectedConfiguration); - mFullTableViewer.refresh(); - } - - /** - * Initialize the UI with the configuration represented by a resource folder name. - * This must be called from the UI thread. - * - * @param folderSegments the segments of the folder name, - * split using {@link FolderConfiguration#QUALIFIER_SEP}. - * @return true if success, or false if the folder name is not a valid name. - */ - public boolean setConfiguration(String[] folderSegments) { - FolderConfiguration config = ResourceManager.getInstance().getConfig(folderSegments); - - if (config == null) { - return false; - } - - setConfiguration(config); - - return true; - } - - /** - * Initialize the UI with the configuration represented by a resource folder name. - * This must be called from the UI thread. - * @param folderName the name of the folder. - * @return true if success, or false if the folder name is not a valid name. - */ - public boolean setConfiguration(String folderName) { - // split the name of the folder in segments. - String[] folderSegments = folderName.split(FolderConfiguration.QUALIFIER_SEP); - - return setConfiguration(folderSegments); - } - - /** - * Gets the configuration as setup by the widget. - * @param config the {@link FolderConfiguration} object to be filled with the information - * from the UI. - */ - public void getConfiguration(FolderConfiguration config) { - config.set(mSelectedConfiguration); - } - - /** - * Returns the state of the configuration being edited/created. - */ - public ConfigurationState getState() { - if (mSelectedConfiguration.getInvalidQualifier() != null) { - return ConfigurationState.INVALID_CONFIG; - } - - if (mSelectedConfiguration.checkRegion() == false) { - return ConfigurationState.REGION_WITHOUT_LANGUAGE; - } - - return ConfigurationState.OK; - } - - /** - * Returns the first invalid qualifier of the configuration being edited/created, - * or null if they are all valid (or if none exists). - *

If {@link #getState()} return {@link ConfigurationState#INVALID_CONFIG} then this will - * not return null. - */ - public ResourceQualifier getInvalidQualifier() { - return mSelectedConfiguration.getInvalidQualifier(); - } - - /** - * Handle changes in the configuration. - * @param keepSelection if true attemps to avoid triggering selection change in - * {@link #mSelectedConfiguration}. - */ - private void onChange(boolean keepSelection) { - ISelection selection = null; - if (keepSelection) { - mOnRefresh = true; - selection = mSelectionTableViewer.getSelection(); - } - - mSelectionTableViewer.refresh(true); - - if (keepSelection) { - mSelectionTableViewer.setSelection(selection); - mOnRefresh = false; - } - - if (mOnChangeListener != null) { - mOnChangeListener.run(); - } - } - - /** - * Content provider around a {@link FolderConfiguration}. - */ - private static class QualifierContentProvider implements IStructuredContentProvider { - - private FolderConfiguration mInput; - - public QualifierContentProvider() { - } - - public void dispose() { - // pass - } - - public Object[] getElements(Object inputElement) { - return mInput.getQualifiers(); - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - mInput = null; - if (newInput instanceof FolderConfiguration) { - mInput = (FolderConfiguration)newInput; - } - } - } - - /** - * Label provider for {@link ResourceQualifier} objects. - */ - private static class QualifierLabelProvider implements ITableLabelProvider { - - private final boolean mShowQualifierValue; - - public QualifierLabelProvider(boolean showQualifierValue) { - mShowQualifierValue = showQualifierValue; - } - - public String getColumnText(Object element, int columnIndex) { - // only one column, so we can ignore columnIndex - if (element instanceof ResourceQualifier) { - if (mShowQualifierValue) { - String value = ((ResourceQualifier)element).getStringValue(); - if (value.length() == 0) { - return String.format("%1$s (?)", - ((ResourceQualifier)element).getShortName()); - } else { - return value; - } - - } else { - return ((ResourceQualifier)element).getShortName(); - } - } - - return null; - } - - public Image getColumnImage(Object element, int columnIndex) { - // only one column, so we can ignore columnIndex - if (element instanceof ResourceQualifier) { - return ((ResourceQualifier)element).getIcon(); - } - - return null; - } - - public void addListener(ILabelProviderListener listener) { - // pass - } - - public void dispose() { - // pass - } - - public boolean isLabelProperty(Object element, String property) { - // pass - return false; - } - - public void removeListener(ILabelProviderListener listener) { - // pass - } - } - - /** - * Base class for Edit widget for {@link ResourceQualifier}. - */ - private abstract static class QualifierEditBase extends Composite { - - public QualifierEditBase(Composite parent, String title) { - super(parent, SWT.NONE); - setLayout(new GridLayout(1, false)); - - new Label(this, SWT.NONE).setText(title); - } - - public abstract void setQualifier(ResourceQualifier qualifier); - } - - /** - * Edit widget for {@link CountryCodeQualifier}. - */ - private class MCCEdit extends QualifierEditBase { - - private Text mText; - - public MCCEdit(Composite parent) { - super(parent, CountryCodeQualifier.NAME); - - mText = new Text(this, SWT.BORDER); - mText.addVerifyListener(new MobileCodeVerifier()); - mText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - onTextChange(); - } - }); - - mText.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - onTextChange(); - } - }); - - new Label(this, SWT.NONE).setText("(3 digit code)"); - } - - private void onTextChange() { - String value = mText.getText(); - - if (value.length() == 0) { - // empty string, means a qualifier with no value. - // Since the qualifier classes are immutable, and we don't want to - // remove the qualifier from the configuration, we create a new default one. - mSelectedConfiguration.setCountryCodeQualifier(new CountryCodeQualifier()); - } else { - try { - CountryCodeQualifier qualifier = CountryCodeQualifier.getQualifier( - CountryCodeQualifier.getFolderSegment(Integer.parseInt(value))); - if (qualifier != null) { - mSelectedConfiguration.setCountryCodeQualifier(qualifier); - } else { - // Failure! Looks like the value is wrong - // (for instance not exactly 3 digits). - mSelectedConfiguration.setCountryCodeQualifier(new CountryCodeQualifier()); - } - } catch (NumberFormatException nfe) { - // Looks like the code is not a number. This should not happen since the text - // field has a VerifyListener that prevents it. - mSelectedConfiguration.setCountryCodeQualifier(new CountryCodeQualifier()); - } - } - - // notify of change - onChange(true /* keepSelection */); - } - - @Override - public void setQualifier(ResourceQualifier qualifier) { - CountryCodeQualifier q = (CountryCodeQualifier)qualifier; - - mText.setText(Integer.toString(q.getCode())); - } - } - - /** - * Edit widget for {@link NetworkCodeQualifier}. - */ - private class MNCEdit extends QualifierEditBase { - private Text mText; - - public MNCEdit(Composite parent) { - super(parent, NetworkCodeQualifier.NAME); - - mText = new Text(this, SWT.BORDER); - mText.addVerifyListener(new MobileCodeVerifier()); - mText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - onTextChange(); - } - }); - mText.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - onTextChange(); - } - }); - - new Label(this, SWT.NONE).setText("(1-3 digit code)"); - } - - private void onTextChange() { - String value = mText.getText(); - - if (value.length() == 0) { - // empty string, means a qualifier with no value. - // Since the qualifier classes are immutable, and we don't want to - // remove the qualifier from the configuration, we create a new default one. - mSelectedConfiguration.setNetworkCodeQualifier(new NetworkCodeQualifier()); - } else { - try { - NetworkCodeQualifier qualifier = NetworkCodeQualifier.getQualifier( - NetworkCodeQualifier.getFolderSegment(Integer.parseInt(value))); - if (qualifier != null) { - mSelectedConfiguration.setNetworkCodeQualifier(qualifier); - } else { - // Failure! Looks like the value is wrong - // (for instance not exactly 3 digits). - mSelectedConfiguration.setNetworkCodeQualifier(new NetworkCodeQualifier()); - } - } catch (NumberFormatException nfe) { - // Looks like the code is not a number. This should not happen since the text - // field has a VerifyListener that prevents it. - mSelectedConfiguration.setNetworkCodeQualifier(new NetworkCodeQualifier()); - } - } - - // notify of change - onChange(true /* keepSelection */); - } - - @Override - public void setQualifier(ResourceQualifier qualifier) { - NetworkCodeQualifier q = (NetworkCodeQualifier)qualifier; - - mText.setText(Integer.toString(q.getCode())); - } - } - - /** - * Edit widget for {@link LanguageQualifier}. - */ - private class LanguageEdit extends QualifierEditBase { - private Combo mLanguage; - - public LanguageEdit(Composite parent) { - super(parent, LanguageQualifier.NAME); - - mLanguage = new Combo(this, SWT.DROP_DOWN); - mLanguage.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - mLanguage.addVerifyListener(new LanguageRegionVerifier()); - mLanguage.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - onLanguageChange(); - } - public void widgetSelected(SelectionEvent e) { - onLanguageChange(); - } - }); - mLanguage.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - onLanguageChange(); - } - }); - - new Label(this, SWT.NONE).setText("(2 letter code)"); - } - - private void onLanguageChange() { - // update the current config - String value = mLanguage.getText(); - - if (value.length() == 0) { - // empty string, means no qualifier. - // Since the qualifier classes are immutable, and we don't want to - // remove the qualifier from the configuration, we create a new default one. - mSelectedConfiguration.setLanguageQualifier(new LanguageQualifier()); - } else { - LanguageQualifier qualifier = null; - String segment = LanguageQualifier.getFolderSegment(value); - if (segment != null) { - qualifier = LanguageQualifier.getQualifier(segment); - } - - if (qualifier != null) { - mSelectedConfiguration.setLanguageQualifier(qualifier); - } else { - // Failure! Looks like the value is wrong (for instance a one letter string). - mSelectedConfiguration.setLanguageQualifier(new LanguageQualifier()); - } - } - - // notify of change - onChange(true /* keepSelection */); - } - - @Override - public void setQualifier(ResourceQualifier qualifier) { - LanguageQualifier q = (LanguageQualifier)qualifier; - - String value = q.getValue(); - if (value != null) { - mLanguage.setText(value); - } - } - } - - /** - * Edit widget for {@link RegionQualifier}. - */ - private class RegionEdit extends QualifierEditBase { - private Combo mRegion; - - public RegionEdit(Composite parent) { - super(parent, RegionQualifier.NAME); - - mRegion = new Combo(this, SWT.DROP_DOWN); - mRegion.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - mRegion.addVerifyListener(new LanguageRegionVerifier()); - mRegion.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - onRegionChange(); - } - public void widgetSelected(SelectionEvent e) { - onRegionChange(); - } - }); - mRegion.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - onRegionChange(); - } - }); - - new Label(this, SWT.NONE).setText("(2 letter code)"); - } - - private void onRegionChange() { - // update the current config - String value = mRegion.getText(); - - if (value.length() == 0) { - // empty string, means no qualifier. - // Since the qualifier classes are immutable, and we don't want to - // remove the qualifier from the configuration, we create a new default one. - mSelectedConfiguration.setRegionQualifier(new RegionQualifier()); - } else { - RegionQualifier qualifier = null; - String segment = RegionQualifier.getFolderSegment(value); - if (segment != null) { - qualifier = RegionQualifier.getQualifier(segment); - } - - if (qualifier != null) { - mSelectedConfiguration.setRegionQualifier(qualifier); - } else { - // Failure! Looks like the value is wrong (for instance a one letter string). - mSelectedConfiguration.setRegionQualifier(new RegionQualifier()); - } - } - - // notify of change - onChange(true /* keepSelection */); - } - - @Override - public void setQualifier(ResourceQualifier qualifier) { - RegionQualifier q = (RegionQualifier)qualifier; - - String value = q.getValue(); - if (value != null) { - mRegion.setText(q.getValue()); - } - } - } - - /** - * Edit widget for {@link ScreenOrientationQualifier}. - */ - private class OrientationEdit extends QualifierEditBase { - - private Combo mOrientation; - - public OrientationEdit(Composite parent) { - super(parent, ScreenOrientationQualifier.NAME); - - mOrientation = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY); - ScreenOrientation[] soValues = ScreenOrientation.values(); - for (ScreenOrientation value : soValues) { - mOrientation.add(value.getDisplayValue()); - } - - mOrientation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - mOrientation.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - onOrientationChange(); - } - public void widgetSelected(SelectionEvent e) { - onOrientationChange(); - } - }); - } - - protected void onOrientationChange() { - // update the current config - int index = mOrientation.getSelectionIndex(); - - if (index != -1) { - mSelectedConfiguration.setScreenOrientationQualifier(new ScreenOrientationQualifier( - ScreenOrientation.getByIndex(index))); - } else { - // empty selection, means no qualifier. - // Since the qualifier classes are immutable, and we don't want to - // remove the qualifier from the configuration, we create a new default one. - mSelectedConfiguration.setScreenOrientationQualifier( - new ScreenOrientationQualifier()); - } - - // notify of change - onChange(true /* keepSelection */); - } - - @Override - public void setQualifier(ResourceQualifier qualifier) { - ScreenOrientationQualifier q = (ScreenOrientationQualifier)qualifier; - - ScreenOrientation value = q.getValue(); - if (value == null) { - mOrientation.clearSelection(); - } else { - mOrientation.select(ScreenOrientation.getIndex(value)); - } - } - } - - /** - * Edit widget for {@link PixelDensityQualifier}. - */ - private class PixelDensityEdit extends QualifierEditBase { - private Text mText; - - public PixelDensityEdit(Composite parent) { - super(parent, PixelDensityQualifier.NAME); - - mText = new Text(this, SWT.BORDER); - mText.addVerifyListener(new DensityVerifier()); - mText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - onTextChange(); - } - }); - mText.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - onTextChange(); - } - }); - } - - private void onTextChange() { - String value = mText.getText(); - - if (value.length() == 0) { - // empty string, means a qualifier with no value. - // Since the qualifier classes are immutable, and we don't want to - // remove the qualifier from the configuration, we create a new default one. - mSelectedConfiguration.setPixelDensityQualifier(new PixelDensityQualifier()); - } else { - try { - PixelDensityQualifier qualifier = PixelDensityQualifier.getQualifier( - PixelDensityQualifier.getFolderSegment(Integer.parseInt(value))); - if (qualifier != null) { - mSelectedConfiguration.setPixelDensityQualifier(qualifier); - } else { - // Failure! Looks like the value is wrong - // (for instance a one letter string). - // We do nothing in this case. - return; - } - } catch (NumberFormatException nfe) { - // Looks like the code is not a number. This should not happen since the text - // field has a VerifyListener that prevents it. - // We do nothing in this case. - return; - } - } - - // notify of change - onChange(true /* keepSelection */); - } - - @Override - public void setQualifier(ResourceQualifier qualifier) { - PixelDensityQualifier q = (PixelDensityQualifier)qualifier; - - mText.setText(Integer.toString(q.getValue())); - } - } - - /** - * Edit widget for {@link TouchScreenQualifier}. - */ - private class TouchEdit extends QualifierEditBase { - - private Combo mTouchScreen; - - public TouchEdit(Composite parent) { - super(parent, TouchScreenQualifier.NAME); - - mTouchScreen = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY); - TouchScreenType[] tstValues = TouchScreenType.values(); - for (TouchScreenType value : tstValues) { - mTouchScreen.add(value.getDisplayValue()); - } - - mTouchScreen.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - mTouchScreen.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - onTouchChange(); - } - public void widgetSelected(SelectionEvent e) { - onTouchChange(); - } - }); - } - - protected void onTouchChange() { - // update the current config - int index = mTouchScreen.getSelectionIndex(); - - if (index != -1) { - mSelectedConfiguration.setTouchTypeQualifier(new TouchScreenQualifier( - TouchScreenType.getByIndex(index))); - } else { - // empty selection, means no qualifier. - // Since the qualifier classes are immutable, and we don't want to - // remove the qualifier from the configuration, we create a new default one. - mSelectedConfiguration.setTouchTypeQualifier(new TouchScreenQualifier()); - } - - // notify of change - onChange(true /* keepSelection */); - } - - @Override - public void setQualifier(ResourceQualifier qualifier) { - TouchScreenQualifier q = (TouchScreenQualifier)qualifier; - - TouchScreenType value = q.getValue(); - if (value == null) { - mTouchScreen.clearSelection(); - } else { - mTouchScreen.select(TouchScreenType.getIndex(value)); - } - } - } - - /** - * Edit widget for {@link KeyboardStateQualifier}. - */ - private class KeyboardEdit extends QualifierEditBase { - - private Combo mKeyboard; - - public KeyboardEdit(Composite parent) { - super(parent, KeyboardStateQualifier.NAME); - - mKeyboard = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY); - KeyboardState[] ksValues = KeyboardState.values(); - for (KeyboardState value : ksValues) { - mKeyboard.add(value.getDisplayValue()); - } - - mKeyboard.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - mKeyboard.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - onKeyboardChange(); - } - public void widgetSelected(SelectionEvent e) { - onKeyboardChange(); - } - }); - } - - protected void onKeyboardChange() { - // update the current config - int index = mKeyboard.getSelectionIndex(); - - if (index != -1) { - mSelectedConfiguration.setKeyboardStateQualifier(new KeyboardStateQualifier( - KeyboardState.getByIndex(index))); - } else { - // empty selection, means no qualifier. - // Since the qualifier classes are immutable, and we don't want to - // remove the qualifier from the configuration, we create a new default one. - mSelectedConfiguration.setKeyboardStateQualifier( - new KeyboardStateQualifier()); - } - - // notify of change - onChange(true /* keepSelection */); - } - - @Override - public void setQualifier(ResourceQualifier qualifier) { - KeyboardStateQualifier q = (KeyboardStateQualifier)qualifier; - - KeyboardState value = q.getValue(); - if (value == null) { - mKeyboard.clearSelection(); - } else { - mKeyboard.select(KeyboardState.getIndex(value)); - } - } - } - - /** - * Edit widget for {@link TextInputMethodQualifier}. - */ - private class TextInputEdit extends QualifierEditBase { - - private Combo mTextInput; - - public TextInputEdit(Composite parent) { - super(parent, TextInputMethodQualifier.NAME); - - mTextInput = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY); - TextInputMethod[] timValues = TextInputMethod.values(); - for (TextInputMethod value : timValues) { - mTextInput.add(value.getDisplayValue()); - } - - mTextInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - mTextInput.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - onTextInputChange(); - } - public void widgetSelected(SelectionEvent e) { - onTextInputChange(); - } - }); - } - - protected void onTextInputChange() { - // update the current config - int index = mTextInput.getSelectionIndex(); - - if (index != -1) { - mSelectedConfiguration.setTextInputMethodQualifier(new TextInputMethodQualifier( - TextInputMethod.getByIndex(index))); - } else { - // empty selection, means no qualifier. - // Since the qualifier classes are immutable, and we don't want to - // remove the qualifier from the configuration, we create a new default one. - mSelectedConfiguration.setTextInputMethodQualifier( - new TextInputMethodQualifier()); - } - - // notify of change - onChange(true /* keepSelection */); - } - - @Override - public void setQualifier(ResourceQualifier qualifier) { - TextInputMethodQualifier q = (TextInputMethodQualifier)qualifier; - - TextInputMethod value = q.getValue(); - if (value == null) { - mTextInput.clearSelection(); - } else { - mTextInput.select(TextInputMethod.getIndex(value)); - } - } - } - - /** - * Edit widget for {@link NavigationMethodQualifier}. - */ - private class NavigationEdit extends QualifierEditBase { - - private Combo mNavigation; - - public NavigationEdit(Composite parent) { - super(parent, NavigationMethodQualifier.NAME); - - mNavigation = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY); - NavigationMethod[] nmValues = NavigationMethod.values(); - for (NavigationMethod value : nmValues) { - mNavigation.add(value.getDisplayValue()); - } - - mNavigation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - mNavigation.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - onNavigationChange(); - } - public void widgetSelected(SelectionEvent e) { - onNavigationChange(); - } - }); - } - - protected void onNavigationChange() { - // update the current config - int index = mNavigation.getSelectionIndex(); - - if (index != -1) { - mSelectedConfiguration.setNavigationMethodQualifier(new NavigationMethodQualifier( - NavigationMethod.getByIndex(index))); - } else { - // empty selection, means no qualifier. - // Since the qualifier classes are immutable, and we don't want to - // remove the qualifier from the configuration, we create a new default one. - mSelectedConfiguration.setNavigationMethodQualifier( - new NavigationMethodQualifier()); - } - - // notify of change - onChange(true /* keepSelection */); - } - - @Override - public void setQualifier(ResourceQualifier qualifier) { - NavigationMethodQualifier q = (NavigationMethodQualifier)qualifier; - - NavigationMethod value = q.getValue(); - if (value == null) { - mNavigation.clearSelection(); - } else { - mNavigation.select(NavigationMethod.getIndex(value)); - } - } - } - - /** - * Edit widget for {@link ScreenDimensionQualifier}. - */ - private class ScreenDimensionEdit extends QualifierEditBase { - - private Text mSize1; - private Text mSize2; - - public ScreenDimensionEdit(Composite parent) { - super(parent, ScreenDimensionQualifier.NAME); - - ModifyListener modifyListener = new ModifyListener() { - public void modifyText(ModifyEvent e) { - onSizeChange(); - } - }; - - FocusAdapter focusListener = new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - onSizeChange(); - } - }; - - mSize1 = new Text(this, SWT.BORDER); - mSize1.addVerifyListener(new DimensionVerifier()); - mSize1.addModifyListener(modifyListener); - mSize1.addFocusListener(focusListener); - - mSize2 = new Text(this, SWT.BORDER); - mSize2.addVerifyListener(new DimensionVerifier()); - mSize2.addModifyListener(modifyListener); - mSize2.addFocusListener(focusListener); - } - - private void onSizeChange() { - // update the current config - String size1 = mSize1.getText(); - String size2 = mSize2.getText(); - - if (size1.length() == 0 || size2.length() == 0) { - // if one of the strings is empty, reset to no qualifier. - // Since the qualifier classes are immutable, and we don't want to - // remove the qualifier from the configuration, we create a new default one. - mSelectedConfiguration.setScreenDimensionQualifier(new ScreenDimensionQualifier()); - } else { - ScreenDimensionQualifier qualifier = ScreenDimensionQualifier.getQualifier(size1, - size2); - - if (qualifier != null) { - mSelectedConfiguration.setScreenDimensionQualifier(qualifier); - } else { - // Failure! Looks like the value is wrong, reset the qualifier - // Since the qualifier classes are immutable, and we don't want to - // remove the qualifier from the configuration, we create a new default one. - mSelectedConfiguration.setScreenDimensionQualifier( - new ScreenDimensionQualifier()); - } - } - - // notify of change - onChange(true /* keepSelection */); - } - - @Override - public void setQualifier(ResourceQualifier qualifier) { - ScreenDimensionQualifier q = (ScreenDimensionQualifier)qualifier; - - mSize1.setText(Integer.toString(q.getValue1())); - mSize2.setText(Integer.toString(q.getValue2())); - } - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ReferenceChooserDialog.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ReferenceChooserDialog.java deleted file mode 100644 index 6913ce0..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ReferenceChooserDialog.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.editors.wizards; - -import com.android.ide.eclipse.adt.AdtPlugin; -import com.android.ide.eclipse.common.resources.IResourceRepository; -import com.android.ide.eclipse.common.resources.ResourceItem; -import com.android.ide.eclipse.common.resources.ResourceType; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.DialogSettings; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.TreePath; -import org.eclipse.jface.viewers.TreeSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.ui.dialogs.FilteredTree; -import org.eclipse.ui.dialogs.PatternFilter; -import org.eclipse.ui.dialogs.SelectionStatusDialog; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * A dialog to let the user choose a reference to a resource. - * - */ -public class ReferenceChooserDialog extends SelectionStatusDialog { - - private static Pattern sResourcePattern = Pattern.compile("@(.*)/(.+)"); //$NON-NLS-1$ - private static Pattern sInlineIdResourcePattern = Pattern.compile("@\\+id/(.+)"); //$NON-NLS-1$ - - private static IDialogSettings sDialogSettings = new DialogSettings(""); - - private IResourceRepository mResources; - private String mCurrentResource; - - private FilteredTree mFilteredTree; - - /** - * @param parent - */ - public ReferenceChooserDialog(IResourceRepository resources, Shell parent) { - super(parent); - - int shellStyle = getShellStyle(); - setShellStyle(shellStyle | SWT.MAX | SWT.RESIZE); - - setTitle("Reference Dialog"); - setMessage(String.format("Choose a resource")); - mResources = resources; - - setDialogBoundsSettings(sDialogSettings, getDialogBoundsStrategy()); - } - - public void setCurrentResource(String resource) { - mCurrentResource = resource; - } - - public String getCurrentResource() { - return mCurrentResource; - } - - - /* (non-Javadoc) - * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult() - */ - @Override - protected void computeResult() { - // get the selection - TreePath treeSelection = getSelection(); - if (treeSelection != null) { - if (treeSelection.getSegmentCount() == 2) { - // get the resource type and the resource item - ResourceType resourceType = (ResourceType)treeSelection.getFirstSegment(); - ResourceItem resourceItem = (ResourceItem)treeSelection.getLastSegment(); - - mCurrentResource = resourceType.getXmlString(resourceItem, false /* system */); - } - } - } - - @Override - protected Control createDialogArea(Composite parent) { - Composite top = (Composite)super.createDialogArea(parent); - - // create the standard message area - createMessageArea(top); - - // create the filtered tree - createFilteredTree(top); - - // setup the initial selection - setupInitialSelection(); - - return top; - } - - private void createFilteredTree(Composite parent) { - mFilteredTree = new FilteredTree(parent, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION, - new PatternFilter()); - - GridData data = new GridData(); - data.widthHint = convertWidthInCharsToPixels(60); - data.heightHint = convertHeightInCharsToPixels(18); - data.grabExcessVerticalSpace = true; - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - data.verticalAlignment = GridData.FILL; - mFilteredTree.setLayoutData(data); - mFilteredTree.setFont(parent.getFont()); - - TreeViewer treeViewer = mFilteredTree.getViewer(); - Tree tree = treeViewer.getTree(); - - tree.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - handleDoubleClick(); - } - - public void widgetSelected(SelectionEvent e) { - handleSelection(); - } - }); - - treeViewer.setLabelProvider(new ResourceLabelProvider()); - treeViewer.setContentProvider(new ResourceContentProvider(false /* fullLevels */)); - treeViewer.setInput(mResources); - } - - protected void handleSelection() { - validateCurrentSelection(); - } - - protected void handleDoubleClick() { - if (validateCurrentSelection()) { - buttonPressed(IDialogConstants.OK_ID); - } - } - - /** - * Returns the selected item in the tree as a {@link TreePath} object. - * @return the TreePath object or null if there was no selection. - */ - private TreePath getSelection() { - ISelection selection = mFilteredTree.getViewer().getSelection(); - if (selection instanceof TreeSelection) { - TreeSelection treeSelection = (TreeSelection)selection; - TreePath[] treePaths = treeSelection.getPaths(); - - // the selection mode is SWT.SINGLE, so we just get the first one. - if (treePaths.length > 0) { - return treePaths[0]; - } - } - - return null; - } - - private boolean validateCurrentSelection() { - TreePath treeSelection = getSelection(); - - IStatus status; - if (treeSelection != null) { - if (treeSelection.getSegmentCount() == 2) { - status = new Status(IStatus.OK, AdtPlugin.PLUGIN_ID, - IStatus.OK, "", //$NON-NLS-1$ - null); - } else { - status = new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, - IStatus.ERROR, "You must select a Resource Item", - null); - } - } else { - status = new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, - IStatus.ERROR, "", //$NON-NLS-1$ - null); - } - - updateStatus(status); - - return status.isOK(); - } - - /** - * Sets up the initial selection. - *

- * This parses {@link #mCurrentResource} to find out the resource type and the resource name. - */ - private void setupInitialSelection() { - // checks the inline id pattern first as it's more restrictive than the other one. - Matcher m = sInlineIdResourcePattern.matcher(mCurrentResource); - if (m.matches()) { - // get the matching name - String resourceName = m.group(1); - - // setup initial selection - setupInitialSelection(ResourceType.ID, resourceName); - } else { - // attempts the inline id pattern - m = sResourcePattern.matcher(mCurrentResource); - if (m.matches()) { - // get the resource type. - ResourceType resourceType = ResourceType.getEnum(m.group(1)); - if (resourceType != null) { - // get the matching name - String resourceName = m.group(2); - - // setup initial selection - setupInitialSelection(resourceType, resourceName); - } - } - } - } - - /** - * Sets up the initial selection based on a {@link ResourceType} and a resource name. - * @param resourceType the resource type. - * @param resourceName the resource name. - */ - private void setupInitialSelection(ResourceType resourceType, String resourceName) { - // get all the resources of this type - ResourceItem[] resourceItems = mResources.getResources(resourceType); - - for (ResourceItem resourceItem : resourceItems) { - if (resourceName.equals(resourceItem.getName())) { - // name of the resource match, we select it, - TreePath treePath = new TreePath(new Object[] { resourceType, resourceItem }); - mFilteredTree.getViewer().setSelection(new TreeSelection(treePath)); - - // and we're done. - return; - } - } - - // if we get here, the resource type is valid, but the resource is missing. - // we select and expand the resource type element. - TreePath treePath = new TreePath(new Object[] { resourceType }); - mFilteredTree.getViewer().setSelection(new TreeSelection(treePath)); - mFilteredTree.getViewer().setExpandedState(resourceType, true /* expanded */); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ResourceChooser.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ResourceChooser.java deleted file mode 100644 index 60a627b..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ResourceChooser.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.editors.wizards; - -import com.android.ide.eclipse.common.resources.IResourceRepository; -import com.android.ide.eclipse.common.resources.ResourceItem; -import com.android.ide.eclipse.common.resources.ResourceType; - -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.dialogs.AbstractElementListSelectionDialog; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * A dialog to let the user select a resource based on a resource type. - */ -public class ResourceChooser extends AbstractElementListSelectionDialog { - - private Pattern mProjectResourcePattern; - - private ResourceType mResourceType; - - private IResourceRepository mProjectResources; - - // TODO: enable when we can display the system resources. - // private Pattern mSystemResourcePattern; - // private IResourceRepository mSystemResources; - // private Button mProjectButton; - // private Button mSystemButton; - - private String mCurrentResource; - - /** - * Creates a Resource Chooser dialog. - * @param type The type of the resource to choose - * @param project The repository for the project - * @param system The System resource repository - * @param parent the parent shell - */ - public ResourceChooser(ResourceType type, IResourceRepository project, - IResourceRepository system, Shell parent) { - super(parent, new ResourceLabelProvider()); - - mResourceType = type; - mProjectResources = project; - // TODO: enable when we can display the system resources. - // mSystemResources = system; - - mProjectResourcePattern = Pattern.compile( - "@" + mResourceType.getName() + "/(.+)"); //$NON-NLS-1$ //$NON-NLS-2$ - // TODO: enable when we can display the system resources. - // mSystemResourcePattern = Pattern.compile( - // "@android:" + mResourceType.getName() + "/(.+)"); //$NON-NLS-1$ //$NON-NLS-2$ - - setTitle("Resource Chooser"); - setMessage(String.format("Choose a %1$s resource", - mResourceType.getDisplayName().toLowerCase())); - } - - public void setCurrentResource(String resource) { - mCurrentResource = resource; - } - - public String getCurrentResource() { - return mCurrentResource; - } - - @Override - protected void computeResult() { - Object[] elements = getSelectedElements(); - if (elements.length == 1 && elements[0] instanceof ResourceItem) { - ResourceItem item = (ResourceItem)elements[0]; - - mCurrentResource = mResourceType.getXmlString(item, - // TODO: enable when we can display the system resources. - false /*mSystemButton.getSelection()*/); - } - } - - @Override - protected Control createDialogArea(Composite parent) { - Composite top = (Composite)super.createDialogArea(parent); - - createMessageArea(top); - - // TODO: enable when we can display the system resources. - // createButtons(top); - - createFilterText(top); - createFilteredList(top); - - setupResourceListAndCurrent(); - - return top; - } - - /** - * Creates the radio button to switch between project and system resources. - * @param top the parent composite - */ - /* TODO: enable when we can display the system resources. - private void createButtons(Composite top) { - mProjectButton = new Button(top, SWT.RADIO); - mProjectButton.setText("Project Resources"); - mProjectButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - super.widgetSelected(e); - setListElements(mProjectResources.getResources(mResourceType)); - } - }); - mSystemButton = new Button(top, SWT.RADIO); - mSystemButton.setText("System Resources"); - mSystemButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - super.widgetSelected(e); - setListElements(mSystemResources.getResources(mResourceType)); - } - }); - } - */ - - /** - * Setups the current list based on the current resource. - */ - private void setupResourceListAndCurrent() { - if (setupInitialSelection(mProjectResourcePattern, mProjectResources) == false) { - // if we couldn't understand the current value, we default to the project resources - ResourceItem[] items = mProjectResources.getResources(mResourceType); - setListElements(items); - } - /* - * TODO: enable when we can display the system resources. - if (setupInitialSelection(mProjectResourcePattern, mProjectResources) == false) { - if (setupInitialSelection(mSystemResourcePattern, mSystemResources) == false) { - // if we couldn't understand the current value, we default to the project resources - IResourceItem[] items = mProjectResources.getResources(mResourceType); - setListElements(items); - mProjectButton.setSelection(true); - } else { - mSystemButton.setSelection(true); - } - } else { - mProjectButton.setSelection(true); - }*/ - } - - /** - * Attempts to setup the list of element from a repository if the current resource - * matches the provided pattern. - * @param pattern the pattern to test the current value - * @param repository the repository to use if the pattern matches. - * @return true if success. - */ - private boolean setupInitialSelection(Pattern pattern, IResourceRepository repository) { - Matcher m = pattern.matcher(mCurrentResource); - if (m.matches()) { - // we have a project resource, let's setup the list - ResourceItem[] items = repository.getResources(mResourceType); - setListElements(items); - - // and let's look for the item we found - String name = m.group(1); - - for (ResourceItem item : items) { - if (name.equals(item.getName())) { - setSelection(new Object[] { item }); - break; - } - } - return true; - } - return false; - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ResourceContentProvider.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ResourceContentProvider.java deleted file mode 100644 index 7c6a539..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ResourceContentProvider.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.editors.wizards; - -import com.android.ide.eclipse.common.resources.IResourceRepository; -import com.android.ide.eclipse.common.resources.ResourceItem; -import com.android.ide.eclipse.common.resources.ResourceType; -import com.android.ide.eclipse.editors.resources.manager.ConfigurableResourceItem; -import com.android.ide.eclipse.editors.resources.manager.ResourceFile; - -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; - -/** - * Content provider for the Resource Explorer TreeView. - * Each level of the tree is represented by a different class. - *

    - *
  • {@link ResourceType}. This represents the list of existing Resource Type present - * in the resources. This can be matched to the subclasses inside the class R - *
  • - *
      - *
    • {@link ResourceItem}. This represents one resource (which can existing in various alternate - * versions). This is similar to the resource Ids defined as R.sometype.id. - *
    • - *
        - *
      • {@link ResourceFile}. (optional) This represents a particular version of the - * {@link ResourceItem}. It is displayed as a list of resource qualifier. - *
      • - *
      - *
    - *
- * - * @see ResourceLabelProvider - */ -public class ResourceContentProvider implements ITreeContentProvider { - - /** - * The current ProjectResources being displayed. - */ - private IResourceRepository mResources; - - private boolean mFullLevels; - - /** - * Constructs a new content providers for resource display. - * @param fullLevels if true the content provider will suppport all 3 levels. If - * false, only two levels are provided. - */ - public ResourceContentProvider(boolean fullLevels) { - mFullLevels = fullLevels; - } - - public Object[] getChildren(Object parentElement) { - if (parentElement instanceof ResourceType) { - return mResources.getResources((ResourceType)parentElement); - } else if (mFullLevels && parentElement instanceof ConfigurableResourceItem) { - return ((ConfigurableResourceItem)parentElement).getSourceFileArray(); - } - return null; - } - - public Object getParent(Object element) { - // pass - return null; - } - - public boolean hasChildren(Object element) { - if (element instanceof ResourceType) { - return mResources.hasResources((ResourceType)element); - } else if (mFullLevels && element instanceof ConfigurableResourceItem) { - return ((ConfigurableResourceItem)element).hasAlternates(); - } - return false; - } - - public Object[] getElements(Object inputElement) { - if (inputElement instanceof IResourceRepository) { - if ((IResourceRepository)inputElement == mResources) { - // get the top level resources. - return mResources.getAvailableResourceTypes(); - } - } - - return new Object[0]; - } - - public void dispose() { - // pass - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - if (newInput instanceof IResourceRepository) { - mResources = (IResourceRepository)newInput; - } - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ResourceLabelProvider.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ResourceLabelProvider.java deleted file mode 100644 index 024d084..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/editors/wizards/ResourceLabelProvider.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.editors.wizards; - -import com.android.ide.eclipse.common.resources.IIdResourceItem; -import com.android.ide.eclipse.common.resources.ResourceItem; -import com.android.ide.eclipse.common.resources.ResourceType; -import com.android.ide.eclipse.editors.resources.manager.ConfigurableResourceItem; -import com.android.ide.eclipse.editors.resources.manager.IdResourceItem; -import com.android.ide.eclipse.editors.resources.manager.ResourceFile; - -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.PlatformUI; - -/** - * Label provider for the Resource Explorer TreeView. - * Each level of the tree is represented by a different class. - *
    - *
  • {@link ResourceType}. This represents the list of existing Resource Type present - * in the resources. This can be matched to the subclasses inside the class R - *
  • - *
      - *
    • {@link ResourceItem}. This represents one resource. The actual type can be - * {@link ConfigurableResourceItem} (which can exist in various alternate versions), - * or {@link IdResourceItem}. - * This is similar to the resource Ids defined as R.sometype.id. - *
    • - *
        - *
      • {@link ResourceFile}. This represents a particular version of the {@link ResourceItem}. - * It is displayed as a list of resource qualifier. - *
      • - *
      - *
    - *
- * - * @see ResourceContentProvider - */ -public class ResourceLabelProvider implements ILabelProvider, ITableLabelProvider { - private Image mWarningImage; - - public ResourceLabelProvider() { - mWarningImage = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( - ISharedImages.IMG_OBJS_WARN_TSK).createImage(); - } - - /** - * @see #getColumnImage(Object, int) - */ - public Image getImage(Object element) { - // pass - return null; - } - - /** - * @see #getColumnText(Object, int) - */ - public String getText(Object element) { - return getColumnText(element, 0); - } - - public void addListener(ILabelProviderListener listener) { - // pass - } - - public void dispose() { - mWarningImage.dispose(); - } - - public boolean isLabelProperty(Object element, String property) { - return false; - } - - public void removeListener(ILabelProviderListener listener) { - // pass - } - - public Image getColumnImage(Object element, int columnIndex) { - if (columnIndex == 1) { - if (element instanceof ConfigurableResourceItem) { - ConfigurableResourceItem item = (ConfigurableResourceItem)element; - if (item.hasDefault() == false) { - return mWarningImage; - } - } - } - return null; - } - - public String getColumnText(Object element, int columnIndex) { - switch (columnIndex) { - case 0: - if (element instanceof ResourceType) { - return ((ResourceType)element).getDisplayName(); - } else if (element instanceof ResourceItem) { - return ((ResourceItem)element).getName(); - } else if (element instanceof ResourceFile) { - return ((ResourceFile)element).getFolder().getConfiguration().toDisplayString(); - } - break; - case 1: - if (element instanceof ConfigurableResourceItem) { - ConfigurableResourceItem item = (ConfigurableResourceItem)element; - int count = item.getAlternateCount(); - if (count > 0) { - if (item.hasDefault()) { - count++; - } - return String.format("%1$d version(s)", count); - } - } else if (element instanceof IIdResourceItem) { - IIdResourceItem idResource = (IIdResourceItem)element; - if (idResource.isDeclaredInline()) { - return "Declared inline"; - } - } - return null; - } - return null; - } -} -- cgit v1.1