com.android.ide.eclipse.adt_22.6.2.v201403212031-1085508

veWorkbenchWindow();
    if (win != null)
    {
      IWorkbenchPage page = win.getActivePage();
      if (page != null) {
        try
        {
          page.showView(viewId, 
            null, 
            activate ? 1 : 2);
        }
        catch (PartInitException localPartInitException) {}
      }
    }
  }
}

/* Location:
 * Qualified Name:     com.android.ide.eclipse.adt.internal.ui.EclipseUiHelper
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ide.eclipse.adt.internal.ui;

public abstract interface IUpdateWizardDialog
{
  public abstract void updateWizardDialog(WizardDialogEx paramWizardDialogEx);
}

/* Location:
 * Qualified Name:     com.android.ide.eclipse.adt.internal.ui.IUpdateWizardDialog
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ide.eclipse.adt.internal.ui;

import com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart;
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
import com.android.resources.ResourceType;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.SelectionStatusDialog;

public class MarginChooser
  extends SelectionStatusDialog
  implements Listener
{
  private GraphicalEditorPart mEditor;
  private AndroidTargetData mTargetData;
  private Text mLeftField;
  private Text mRightField;
  private Text mTopField;
  private Text mBottomField;
  private Text mAllField;
  private String mInitialAll;
  private String mInitialLeft;
  private String mInitialRight;
  private String mInitialTop;
  private String mInitialBottom;
  private Label mErrorLabel;
  private String[] mMargins;
  private static final String PROP_TEXTFIELD = "textField";
  
  public MarginChooser(Shell parent, GraphicalEditorPart editor, AndroidTargetData targetData, String all, String left, String right, String top, String bottom)
  {
    super(parent);
    setTitle("Edit Margins");
    mEditor = editor;
    mTargetData = targetData;
    mInitialAll = all;
    mInitialLeft = left;
    mInitialRight = right;
    mInitialTop = top;
    mInitialBottom = bottom;
  }
  
  protected Control createDialogArea(Composite parent)
  {
    Composite container = new Composite(parent, 0);
    container.setLayoutData(new GridData(4, 4, true, true, 1, 1));
    
    container.setLayout(new GridLayout(3, false));
    
    Label allLabel = new Label(container, 0);
    allLabel.setLayoutData(new GridData(131072, 16777216, false, false, 1, 1));
    allLabel.setText("All:");
    
    mAllField = new Text(container, 18432);
    mAllField.setLayoutData(new GridData(4, 16777216, true, false, 1, 1));
    mAllField.setText(mInitialAll != null ? mInitialAll : "");
    
    Button allButton = new Button(container, 0);
    allButton.setText("Resource...");
    allButton.setData("textField", mAllField);
    
    Label label = new Label(container, 258);
    label.setLayoutData(new GridData(4, 16777216, false, false, 3, 1));
    
    Label leftLabel = new Label(container, 0);
    leftLabel.setLayoutData(new GridData(131072, 16777216, false, false, 1, 1));
    leftLabel.setText("Left:");
    
    mLeftField = new Text(container, 18432);
    mLeftField.setLayoutData(new GridData(4, 16777216, true, false, 1, 1));
    mLeftField.setText(mInitialLeft != null ? mInitialLeft : "");
    
    Button leftButton = new Button(container, 0);
    leftButton.setText("Resource...");
    leftButton.setData("textField", mLeftField);
    
    Label rightLabel = new Label(container, 0);
    rightLabel.setLayoutData(new GridData(131072, 16777216, false, false, 1, 1));
    rightLabel.setText("Right:");
    
    mRightField = new Text(container, 18432);
    mRightField.setLayoutData(new GridData(4, 16777216, true, false, 1, 1));
    mRightField.setText(mInitialRight != null ? mInitialRight : "");
    
    Button rightButton = new Button(container, 0);
    rightButton.setText("Resource...");
    rightButton.setData("textField", mRightField);
    
    Label topLabel = new Label(container, 0);
    topLabel.setLayoutData(new GridData(131072, 16777216, false, false, 1, 1));
    topLabel.setText("Top:");
    
    mTopField = new Text(container, 18432);
    mTopField.setLayoutData(new GridData(4, 16777216, true, false, 1, 1));
    mTopField.setText(mInitialTop != null ? mInitialTop : "");
    
    Button topButton = new Button(container, 0);
    topButton.setText("Resource...");
    topButton.setData("textField", mTopField);
    
    Label bottomLabel = new Label(container, 0);
    bottomLabel.setLayoutData(new GridData(131072, 16777216, false, false, 1, 1));
    bottomLabel.setText("Bottom:");
    
    mBottomField = new Text(container, 18432);
    mBottomField.setLayoutData(new GridData(4, 16777216, true, false, 1, 1));
    mBottomField.setText(mInitialBottom != null ? mInitialBottom : "");
    
    Button bottomButton = new Button(container, 0);
    bottomButton.setText("Resource...");
    bottomButton.setData("textField", mBottomField);
    
    allButton.addListener(13, this);
    leftButton.addListener(13, this);
    rightButton.addListener(13, this);
    topButton.addListener(13, this);
    bottomButton.addListener(13, this);
    
    mAllField.addListener(24, this);
    mLeftField.addListener(24, this);
    mRightField.addListener(24, this);
    mTopField.addListener(24, this);
    mBottomField.addListener(24, this);
    
    new Label(container, 0);
    mErrorLabel = new Label(container, 64);
    mErrorLabel.setLayoutData(new GridData(4, 4, true, false, 2, 1));
    mErrorLabel.setForeground(parent.getDisplay().getSystemColor(3));
    return container;
  }
  
  protected void computeResult()
  {
    mMargins = new String[] {
      mAllField.getText().trim(), 
      mLeftField.getText().trim(), mRightField.getText().trim(), 
      mTopField.getText().trim(), mBottomField.getText().trim() };
  }
  
  public String[] getMargins()
  {
    return mMargins;
  }
  
  public void handleEvent(Event event)
  {
    if (type == 24)
    {
      if ((widget instanceof Text))
      {
        Text text = (Text)widget;
        String input = text.getText().trim();
        boolean isNumber = false;
        try
        {
          if (Integer.parseInt(input) > 0) {
            isNumber = true;
          }
        }
        catch (NumberFormatException localNumberFormatException) {}
        if (isNumber)
        {
          String message = String.format("Hint: Use \"%1$sdp\" instead", new Object[] { input });
          mErrorLabel.setText(message);
        }
        else
        {
          mErrorLabel.setText("");
        }
      }
    }
    else if (type == 13) {
      if ((widget instanceof Button))
      {
        Button button = (Button)widget;
        Text text = (Text)button.getData("textField");
        
        ResourceChooser chooser = ResourceChooser.create(mEditor, ResourceType.DIMEN)
          .setCurrentResource(text.getText().trim());
        if (chooser.open() == 0) {
          text.setText(chooser.getCurrentResource());
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     com.android.ide.eclipse.adt.internal.ui.MarginChooser
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ide.eclipse.adt.internal.ui;

import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;

class ReferenceChooserDialog$1
  implements SelectionListener
{
  ReferenceChooserDialog$1(ReferenceChooserDialog paramReferenceChooserDialog) {}
  
  public void widgetDefaultSelected(SelectionEvent e)
  {
    this$0.handleDoubleClick();
  }
  
  public void widgetSelected(SelectionEvent e)
  {
    this$0.handleSelection();
  }
}

/* Location:
 * Qualified Name:     com.android.ide.eclipse.adt.internal.ui.ReferenceChooserDialog.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ide.eclipse.adt.internal.ui;

import com.android.ide.eclipse.adt.internal.refactorings.extractstring.ExtractStringRefactoring;
import com.android.ide.eclipse.adt.internal.refactorings.extractstring.ExtractStringWizard;
import com.android.resources.ResourceType;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;

class ReferenceChooserDialog$OnNewResButtonSelected
  extends SelectionAdapter
{
  private ReferenceChooserDialog$OnNewResButtonSelected(ReferenceChooserDialog paramReferenceChooserDialog) {}
  
  public void widgetSelected(SelectionEvent e)
  {
    super.widgetSelected(e);
    
    ResourceType type = ReferenceChooserDialog.access$0(this$0);
    if (type == ResourceType.STRING)
    {
      ExtractStringRefactoring ref = new ExtractStringRefactoring(
        ReferenceChooserDialog.access$1(this$0), true);
      RefactoringWizard wizard = new ExtractStringWizard(ref, ReferenceChooserDialog.access$1(this$0));
      RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
      try
      {
        IWorkbench w = PlatformUI.getWorkbench();
        if (op.run(w.getDisplay().getActiveShell(), wizard.getDefaultPageTitle()) == 0)
        {
          ReferenceChooserDialog.access$2(this$0).refresh();
          
          ReferenceChooserDialog.access$3(this$0, type, ref.getXmlStringId());
        }
      }
      catch (InterruptedException localInterruptedException) {}
    }
  }
}

/* Location:
 * Qualified Name:     com.android.ide.eclipse.adt.internal.ui.ReferenceChooserDialog.OnNewResButtonSelected
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ide.eclipse.adt.internal.ui;

import com.android.ide.common.resources.ResourceItem;
import com.android.ide.common.resources.ResourceRepository;
import com.android.ide.eclipse.adt.internal.editors.layout.properties.PropertyFactory;
import com.android.ide.eclipse.adt.internal.refactorings.extractstring.ExtractStringRefactoring;
import com.android.ide.eclipse.adt.internal.refactorings.extractstring.ExtractStringWizard;
import com.android.resources.ResourceType;
import java.util.Collection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.DialogSettings;
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.ltk.ui.refactoring.RefactoringWizard;
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;
import org.eclipse.ui.dialogs.SelectionStatusDialog;

public class ReferenceChooserDialog
  extends SelectionStatusDialog
{
  private static Pattern sResourcePattern = Pattern.compile("@(.*)/(.+)");
  private static Pattern sInlineIdResourcePattern = Pattern.compile("@\\+id/(.+)");
  private static IDialogSettings sDialogSettings = new DialogSettings("");
  private ResourceRepository mProjectResources;
  private String mCurrentResource;
  private FilteredTree mFilteredTree;
  private Button mNewResButton;
  private final IProject mProject;
  private TreeViewer mTreeViewer;
  private ResourcePreviewHelper mPreviewHelper;
  
  public ReferenceChooserDialog(IProject project, ResourceRepository projectResources, Shell parent)
  {
    super(parent);
    mProject = project;
    mProjectResources = projectResources;
    
    int shellStyle = getShellStyle();
    setShellStyle(shellStyle | 0x400 | 0x10);
    
    setTitle("Reference Chooser");
    setMessage(String.format("Choose a resource", new Object[0]));
    
    setDialogBoundsSettings(sDialogSettings, getDialogBoundsStrategy());
  }
  
  public void setPreviewHelper(ResourcePreviewHelper previewHelper)
  {
    mPreviewHelper = previewHelper;
  }
  
  public void setCurrentResource(String resource)
  {
    mCurrentResource = resource;
  }
  
  public String getCurrentResource()
  {
    return mCurrentResource;
  }
  
  protected void computeResult()
  {
    TreePath treeSelection = getSelection();
    if ((treeSelection != null) && 
      (treeSelection.getSegmentCount() == 2))
    {
      ResourceType resourceType = (ResourceType)treeSelection.getFirstSegment();
      ResourceItem resourceItem = (ResourceItem)treeSelection.getLastSegment();
      
      mCurrentResource = resourceItem.getXmlString(resourceType, false);
    }
  }
  
  protected Control createDialogArea(Composite parent)
  {
    Composite top = (Composite)super.createDialogArea(parent);
    
    createMessageArea(top);
    
    createFilteredTree(top);
    if (mCurrentResource != null) {
      setupInitialSelection();
    }
    createNewResButtons(top);
    
    Composite workaround = PropertyFactory.addWorkaround(top);
    if (workaround != null) {
      workaround.setLayoutData(new GridData(16384, 128, false, false, 1, 1));
    }
    return top;
  }
  
  private void createNewResButtons(Composite top)
  {
    mNewResButton = new Button(top, 0);
    mNewResButton.addSelectionListener(new OnNewResButtonSelected(null));
    updateNewResButton();
  }
  
  private void createFilteredTree(Composite parent)
  {
    mFilteredTree = new FilteredTree(parent, 67588, 
      new PatternFilter());
    
    GridData data = new GridData();
    widthHint = convertWidthInCharsToPixels(60);
    heightHint = convertHeightInCharsToPixels(18);
    grabExcessVerticalSpace = true;
    grabExcessHorizontalSpace = true;
    horizontalAlignment = 4;
    verticalAlignment = 4;
    mFilteredTree.setLayoutData(data);
    mFilteredTree.setFont(parent.getFont());
    
    mTreeViewer = mFilteredTree.getViewer();
    Tree tree = mTreeViewer.getTree();
    
    tree.addSelectionListener(new SelectionListener()
    {
      public void widgetDefaultSelected(SelectionEvent e)
      {
        handleDoubleClick();
      }
      
      public void widgetSelected(SelectionEvent e)
      {
        handleSelection();
      }
    });
    mTreeViewer.setLabelProvider(new ResourceLabelProvider());
    mTreeViewer.setContentProvider(new ResourceContentProvider(false));
    mTreeViewer.setInput(mProjectResources);
  }
  
  protected void handleSelection()
  {
    validateCurrentSelection();
    updateNewResButton();
    if (mPreviewHelper != null)
    {
      TreePath treeSelection = getSelection();
      ResourceType type = null;
      if ((treeSelection != null) && (treeSelection.getSegmentCount() == 2))
      {
        Object segment = treeSelection.getSegment(0);
        if ((segment instanceof ResourceType))
        {
          type = (ResourceType)segment;
          
          computeResult();
        }
      }
      mPreviewHelper.updatePreview(type, mCurrentResource);
    }
  }
  
  protected void handleDoubleClick()
  {
    if (validateCurrentSelection()) {
      buttonPressed(0);
    }
  }
  
  private TreePath getSelection()
  {
    ISelection selection = mFilteredTree.getViewer().getSelection();
    if ((selection instanceof TreeSelection))
    {
      TreeSelection treeSelection = (TreeSelection)selection;
      TreePath[] treePaths = treeSelection.getPaths();
      if (treePaths.length > 0) {
        return treePaths[0];
      }
    }
    return null;
  }
  
  private boolean validateCurrentSelection()
  {
    TreePath treeSelection = getSelection();
    IStatus status;
    IStatus status;
    if (treeSelection != null)
    {
      IStatus status;
      if (treeSelection.getSegmentCount() == 2) {
        status = new Status(0, "com.android.ide.eclipse.adt", 
          0, "", 
          null);
      } else {
        status = new Status(4, "com.android.ide.eclipse.adt", 
          4, "You must select a Resource Item", 
          null);
      }
    }
    else
    {
      status = new Status(4, "com.android.ide.eclipse.adt", 
        4, "", 
        null);
    }
    updateStatus(status);
    
    return status.isOK();
  }
  
  private void updateNewResButton()
  {
    ResourceType type = getSelectedResourceType();
    
    mNewResButton.setEnabled(type == ResourceType.STRING);
    
    String title = String.format("New %1$s...", new Object[] {
      type == null ? "Resource" : type.getDisplayName() });
    mNewResButton.setText(title);
    mNewResButton.pack();
  }
  
  private class OnNewResButtonSelected
    extends SelectionAdapter
  {
    private OnNewResButtonSelected() {}
    
    public void widgetSelected(SelectionEvent e)
    {
      super.widgetSelected(e);
      
      ResourceType type = ReferenceChooserDialog.this.getSelectedResourceType();
      if (type == ResourceType.STRING)
      {
        ExtractStringRefactoring ref = new ExtractStringRefactoring(
          mProject, true);
        RefactoringWizard wizard = new ExtractStringWizard(ref, mProject);
        RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
        try
        {
          IWorkbench w = PlatformUI.getWorkbench();
          if (op.run(w.getDisplay().getActiveShell(), wizard.getDefaultPageTitle()) == 0)
          {
            mTreeViewer.refresh();
            
            ReferenceChooserDialog.this.setupInitialSelection(type, ref.getXmlStringId());
          }
        }
        catch (InterruptedException localInterruptedException) {}
      }
    }
  }
  
  private ResourceType getSelectedResourceType()
  {
    ResourceType type = null;
    
    TreePath selection = getSelection();
    if ((selection != null) && (selection.getSegmentCount() > 0))
    {
      Object first = selection.getFirstSegment();
      if ((first instanceof ResourceType)) {
        type = (ResourceType)first;
      }
    }
    return type;
  }
  
  private void setupInitialSelection()
  {
    Matcher m = sInlineIdResourcePattern.matcher(mCurrentResource);
    if (m.matches())
    {
      String resourceName = m.group(1);
      
      setupInitialSelection(ResourceType.ID, resourceName);
    }
    else
    {
      m = sResourcePattern.matcher(mCurrentResource);
      if (m.matches())
      {
        ResourceType resourceType = ResourceType.getEnum(m.group(1));
        if (resourceType != null)
        {
          String resourceName = m.group(2);
          
          setupInitialSelection(resourceType, resourceName);
        }
      }
    }
  }
  
  private void setupInitialSelection(ResourceType resourceType, String resourceName)
  {
    Collection<ResourceItem> resourceItems = 
      mProjectResources.getResourceItemsOfType(resourceType);
    for (ResourceItem resourceItem : resourceItems) {
      if (resourceName.equals(resourceItem.getName()))
      {
        TreePath treePath = new TreePath(new Object[] { resourceType, resourceItem });
        mFilteredTree.getViewer().setSelection(
          new TreeSelection(treePath), 
          true);
        
        return;
      }
    }
    TreePath treePath = new TreePath(new Object[] { resourceType });
    mFilteredTree.getViewer().setSelection(
      new TreeSelection(treePath), 
      true);
    mFilteredTree.getViewer().setExpandedState(resourceType, true);
  }
}

/* Location:
 * Qualified Name:     com.android.ide.eclipse.adt.internal.ui.ReferenceChooserDialog
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ide.eclipse.adt.internal.ui;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.ui.dialogs.FilteredList;

class ResourceChooser$1
  extends SelectionAdapter
{
  ResourceChooser$1(ResourceChooser paramResourceChooser) {}
  
  public void widgetSelected(SelectionEvent e)
  {
    super.widgetSelected(e);
    if (ResourceChooser.access$2(this$0).getSelection())
    {
      ResourceChooser.access$3(this$0).setSelection(new int[0]);
      ResourceChooser.access$4(this$0);
      ResourceChooser.access$5(this$0, false);
      ResourceChooser.access$6(this$0);
    }
  }
}

/* Location:
 * Qualified Name:     com.android.ide.eclipse.adt.internal.ui.ResourceChooser.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ide.eclipse.adt.internal.ui;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.ui.dialogs.FilteredList;

class ResourceChooser$2
  extends SelectionAdapter
{
  ResourceChooser$2(ResourceChooser paramResourceChooser) {}
  
  public void widgetSelected(SelectionEvent e)
  {
    super.widgetSelected(e);
    if (ResourceChooser.access$7(this$0).getSelection())
    {
      ResourceChooser.access$3(this$0).setSelection(new int[0]);
      ResourceChooser.access$4(this$0);
      ResourceChooser.access$5(this$0, true);
      ResourceChooser.access$6(this$0);
    }
  }
}

/* Location:
 * Qualified Name:     com.android.ide.eclipse.adt.internal.ui.ResourceChooser.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ide.eclipse.adt.internal.ui;

import com.android.annotations.NonNull;
import com.android.ide.common.resources.ResourceItem;
import com.android.ide.eclipse.adt.AdtUtils;
import com.android.ide.eclipse.adt.internal.assetstudio.OpenCreateAssetSetWizardAction;
import com.android.ide.eclipse.adt.internal.resources.ResourceHelper;
import com.android.resources.ResourceType;
import java.util.Arrays;
import java.util.List;
import org.eclipse.core.resources.IResource;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.ui.dialogs.FilteredList;

class ResourceChooser$3
  extends SelectionAdapter
{
  ResourceChooser$3(ResourceChooser paramResourceChooser) {}
  
  public void widgetSelected(SelectionEvent e)
  {
    super.widgetSelected(e);
    if (ResourceChooser.access$1(this$0) == ResourceType.STRING)
    {
      String newName = ResourceChooser.access$8(this$0);
      selectAddedItem(newName);
    }
    else if (ResourceChooser.access$1(this$0) == ResourceType.DRAWABLE)
    {
      OpenCreateAssetSetWizardAction action = 
        new OpenCreateAssetSetWizardAction(ResourceChooser.access$0(this$0));
      action.run();
      List<IResource> files = action.getCreatedFiles();
      if ((files != null) && (files.size() > 0))
      {
        String newName = AdtUtils.stripAllExtensions(((IResource)files.get(0)).getName());
        
        ResourceItem[] items = ResourceChooser.access$4(this$0);
        ResourceChooser.access$9(this$0, newName, items);
      }
    }
    else if (ResourceHelper.isValueBasedResourceType(ResourceChooser.access$1(this$0)))
    {
      String newName = ResourceChooser.access$10(this$0, ResourceChooser.access$1(this$0));
      if (newName != null) {
        selectAddedItem(newName);
      }
    }
    else
    {
      String newName = ResourceChooser.access$11(this$0, ResourceChooser.access$1(this$0));
      if (newName != null) {
        selectAddedItem(newName);
      }
    }
  }
  
  private void selectAddedItem(@NonNull String newName)
  {
    ResourceItem[] items = ResourceChooser.access$4(this$0);
    
    boolean found = false;
    ResourceItem[] arrayOfResourceItem1;
    int j = (arrayOfResourceItem1 = items).length;
    for (int i = 0; i < j; i++)
    {
      ResourceItem item = arrayOfResourceItem1[i];
      if (newName.equals(item.getName()))
      {
        found = true;
        break;
      }
    }
    if (!found)
    {
      ResourceItem[] newItems = new ResourceItem[items.length + 1];
      System.arraycopy(items, 0, newItems, 0, items.length);
      newItems[items.length] = new ResourceItem(newName);
      items = newItems;
      Arrays.sort(items);
      ResourceChooser.access$12(this$0, items);
      ResourceChooser.access$3(this$0).setEnabled(newItems.length > 0);
    }
    ResourceChooser.access$9(this$0, newName, items);
  }
}

/* Location:
 * Qualified Name:     com.android.ide.eclipse.adt.internal.ui.ResourceChooser.3
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ide.eclipse.adt.internal.ui;

import com.android.ide.eclipse.adt.internal.resources.ResourceNameValidator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.SelectionStatusDialog;

class ResourceChooser$NameValueDialog
  extends SelectionStatusDialog
  implements Listener
{
  private Text mNameText;
  private Text mValueText;
  private String mInitialName;
  private String mName;
  private String mValue;
  private ResourceNameValidator mValidator;
  
  public ResourceChooser$NameValueDialog(ResourceChooser paramResourceChooser, Shell parent, String initialName)
  {
    super(parent);
    mInitialName = initialName;
  }
  
  protected Control createDialogArea(Composite parent)
  {
    Composite container = new Composite(parent, 0);
    container.setLayout(new GridLayout(2, false));
    GridData gridData = new GridData(4, 4, true, true, 1, 1);
    
    widthHint = 500;
    container.setLayoutData(gridData);
    
    Label nameLabel = new Label(container, 0);
    nameLabel.setLayoutData(new GridData(131072, 16777216, false, false, 1, 1));
    nameLabel.setText("Name:");
    
    mNameText = new Text(container, 2048);
    mNameText.setLayoutData(new GridData(4, 16777216, true, false, 1, 1));
    if (mInitialName != null)
    {
      mNameText.setText(mInitialName);
      mNameText.selectAll();
    }
    Label valueLabel = new Label(container, 0);
    valueLabel.setLayoutData(new GridData(131072, 16777216, false, false, 1, 1));
    valueLabel.setText("Value:");
    
    mValueText = new Text(container, 2048);
    mValueText.setLayoutData(new GridData(4, 16777216, true, false, 1, 1));
    
    mNameText.addListener(24, this);
    mValueText.addListener(24, this);
    
    validate();
    
    return container;
  }
  
  protected void computeResult()
  {
    mName = mNameText.getText().trim();
    mValue = mValueText.getText().trim();
  }
  
  private String getName()
  {
    return mName;
  }
  
  private String getValue()
  {
    return mValue;
  }
  
  public void handleEvent(Event event)
  {
    validate();
  }
  
  private void validate()
  {
    computeResult();
    IStatus status;
    IStatus status;
    if (mName.length() == 0)
    {
      status = new Status(4, "com.android.ide.eclipse.adt", "Enter a name");
    }
    else
    {
      IStatus status;
      if (mValue.length() == 0)
      {
        status = new Status(4, "com.android.ide.eclipse.adt", "Enter a value");
      }
      else
      {
        if (mValidator == null) {
          mValidator = ResourceNameValidator.create(false, ResourceChooser.access$0(this$0), ResourceChooser.access$1(this$0));
        }
        String error = mValidator.isValid(mName);
        IStatus status;
        if (error != null) {
          status = new Status(4, "com.android.ide.eclipse.adt", error);
        } else {
          status = new Status(0, "com.android.ide.eclipse.adt", null);
        }
      }
    }
    updateStatus(status);
  }
}

/* Location:
 * Qualified Name:     com.android.ide.eclipse.adt.internal.ui.ResourceChooser.NameValueDialog
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.ide.eclipse.adt.internal.ui;

import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.android.ide.common.rendering.api.ResourceValue;
import com.android.ide.common.resources.ResourceItem;
import com.android.ide.common.resources.ResourceRepository;
import com.android.ide.common.resources.ResourceResolver;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.AdtUtils;
import com.android.ide.eclipse.adt.internal.assetstudio.OpenCreateAssetSetWizardAction;
import com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor;
import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate;
import com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart;
import com.android.ide.eclipse.adt.internal.editors.layout.gle2.LayoutCanvas;
import com.android.ide.eclipse.adt.internal.editors.layout.properties.PropertyFactory;
import com.android.ide.eclipse.adt.internal.refactorings.extractstring.ExtractStringRefactoring;
import com.android.ide.eclipse.adt.internal.refactorings.extractstring.ExtractStringWizard;
import com.android.ide.eclipse.adt.internal.resources.ResourceHelper;
import com.android.ide.eclipse.adt.internal.resources.ResourceNameValidator;
import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources;
import com.android.ide.eclipse.adt.internal.resources.manager.ResourceManager;
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
import com.android.ide.eclipse.adt.internal.sdk.ProjectState;
import com.android.ide.eclipse.adt.internal.sdk.Sdk;
import com.android.resources.ResourceType;
import com.android.utils.Pair;
import com.google.common.collect.Maps;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.text.IRegion;
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
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.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.AbstractElementListSelectionDialog;
import org.eclipse.ui.dialogs.FilteredList;
import org.eclipse.ui.dialogs.SelectionStatusDialog;

public class ResourceChooser
  extends AbstractElementListSelectionDialog
  implements ModifyListener
{
  public static final int CLEAR_RETURN_CODE = -5;
  private static final int CLEAR_BUTTON_ID = -5;
  private Pattern mProjectResourcePattern;
  private ResourceType mResourceType;
  private final List<ResourceRepository> mProjectResources;
  private final ResourceRepository mFrameworkResources;
  private Pattern mSystemResourcePattern;
  private Button mProjectButton;
  private Button mSystemButton;
  private Button mNewButton;
  private String mCurrentResource;
  private final IProject mProject;
  private IInputValidator mInputValidator;
  private ResourcePreviewHelper mPreviewHelper;
  private Text mEditValueText;
  private boolean mShowValueText;
  private boolean mFirstSelect = true;
  private Label mResolvedLabel;
  private ResourceResolver mResourceResolver;
  
  private ResourceChooser(@NonNull IProject project, @NonNull ResourceType type, @NonNull List<ResourceRepository> projectResources, @Nullable ResourceRepository frameworkResources, @NonNull Shell parent)
  {
    super(parent, new ResourceLabelProvider());
    mProject = project;
    
    mResourceType = type;
    mProjectResources = projectResources;
    mFrameworkResources = frameworkResources;
    
    mProjectResourcePattern = Pattern.compile(
      "@" + mResourceType.getName() + "/(.+)");
    
    mSystemResourcePattern = Pattern.compile(
      "@android:" + mResourceType.getName() + "/(.+)");
    
    setTitle("Resource Chooser");
    setMessage(String.format("Choose a %1$s resource", new Object[] {
      mResourceType.getDisplayName().toLowerCase(Locale.US) }));
  }
  
  @NonNull
  public static ResourceChooser create(@NonNull GraphicalEditorPart editor, @NonNull ResourceType type)
  {
    IProject project = editor.getProject();
    Shell parent = editor.getCanvasControl().getShell();
    AndroidTargetData targetData = editor.getEditorDelegate().getEditor().getTargetData();
    ResourceChooser chooser = create(project, type, targetData, parent);
    if (type == ResourceType.STRING)
    {
      chooser.setResourceResolver(editor.getResourceResolver());
      chooser.setShowValueText(true);
    }
    else if ((type == ResourceType.DIMEN) || (type == ResourceType.INTEGER))
    {
      chooser.setResourceResolver(editor.getResourceResolver());
    }
    chooser.setPreviewHelper(new ResourcePreviewHelper(chooser, editor));
    return chooser;
  }
  
  @NonNull
  public static ResourceChooser create(@NonNull IProject project, @NonNull ResourceType type, @Nullable AndroidTargetData targetData, @NonNull Shell parent)
  {
    ResourceManager manager = ResourceManager.getInstance();
    
    List<ResourceRepository> projectResources = new ArrayList();
    ProjectResources resources = manager.getProjectResources(project);
    projectResources.add(resources);
    
    ProjectState projectState = Sdk.getProjectState(project);
    if (projectState != null)
    {
      List<IProject> libraries = projectState.getFullLibraryProjects();
      if ((libraries != null) && (!libraries.isEmpty())) {
        for (IProject library : libraries) {
          projectResources.add(manager.getProjectResources(library));
        }
      }
    }
    ResourceRepository frameworkResources = 
      targetData != null ? targetData.getFrameworkResources() : null;
    return new ResourceChooser(project, type, projectResources, frameworkResources, parent);
  }
  
  public ResourceChooser setShowValueText(boolean showValueText)
  {
    mShowValueText = showValueText;
    
    return this;
  }
  
  public ResourceChooser setResourceResolver(ResourceResolver resourceResolver)
  {
    mResourceResolver = resourceResolver;
    
    return this;
  }
  
  public ResourceChooser setPreviewHelper(ResourcePreviewHelper previewHelper)
  {
    mPreviewHelper = previewHelper;
    
    return this;
  }
  
  public ResourceChooser setInitialSize(int width, int height)
  {
    setSize(width, height);
    
    return this;
  }
  
  public void create()
  {
    super.create();
    if (mShowValueText)
    {
      mEditValueText.selectAll();
      mEditValueText.setFocus();
    }
  }
  
  protected void createButtonsForButtonBar(Composite parent)
  {
    createButton(parent, -5, "Clear", false);
    super.createButtonsForButtonBar(parent);
  }
  
  protected void buttonPressed(int buttonId)
  {
    super.buttonPressed(buttonId);
    if (buttonId == -5)
    {
      setReturnCode(-5);
      close();
    }
  }
  
  public ResourceChooser setCurrentResource(@Nullable String resource)
  {
    mCurrentResource = resource;
    if ((mShowValueText) && (mEditValueText != null)) {
      mEditValueText.setText(resource);
    }
    return this;
  }
  
  @Nullable
  public String getCurrentResource()
  {
    return mCurrentResource;
  }
  
  public ResourceChooser setInputValidator(@Nullable IInputValidator inputValidator)
  {
    mInputValidator = inputValidator;
    
    return this;
  }
  
  protected void computeResult()
  {
    if (mShowValueText)
    {
      mCurrentResource = mEditValueText.getText();
      if (mCurrentResource.length() == 0) {
        mCurrentResource = null;
      }
      return;
    }
    computeResultFromSelection();
  }
  
  private void computeResultFromSelection()
  {
    if (getSelectionIndex() == -1)
    {
      mCurrentResource = null;
      return;
    }
    Object[] elements = getSelectedElements();
    if ((elements.length == 1) && ((elements[0] instanceof ResourceItem)))
    {
      ResourceItem item = (ResourceItem)elements[0];
      
      mCurrentResource = item.getXmlString(mResourceType, mSystemButton.getSelection());
      if ((mInputValidator != null) && (mInputValidator.isValid(mCurrentResource) != null)) {
        mCurrentResource = null;
      }
    }
  }
  
  protected Control createDialogArea(Composite parent)
  {
    Composite top = (Composite)super.createDialogArea(parent);
    
    createMessageArea(top);
    
    createButtons(top);
    createFilterText(top);
    createFilteredList(top);
    
    createNewResButtons(top);
    
    createValueField(top);
    
    setupResourceList();
    selectResourceString(mCurrentResource);
    
    return top;
  }
  
  private void createButtons(Composite top)
  {
    mProjectButton = new Button(top, 16);
    mProjectButton.setText("Project Resources");
    mProjectButton.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        super.widgetSelected(e);
        if (mProjectButton.getSelection())
        {
          fFilteredList.setSelection(new int[0]);
          ResourceChooser.this.setupResourceList();
          ResourceChooser.this.updateNewButton(false);
          ResourceChooser.this.updateValue();
        }
      }
    });
    mSystemButton = new Button(top, 16);
    mSystemButton.setText("System Resources");
    mSystemButton.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
      {
        super.widgetSelected(e);
        if (mSystemButton.getSelection())
        {
          fFilteredList.setSelection(new int[0]);
          ResourceChooser.this.setupResourceList();
          ResourceChooser.this.updateNewButton(true);
          ResourceChooser.this.updateValue();
        }
      }
    });
    if (mFrameworkResources == null) {
      mSystemButton.setVisible(false);
    }
  }
  
  private void createNewResButtons(Composite top)
  {
    mNewButton = new Button(top, 0);
    
    String title = String.format("New %1$s...", new Object[] { mResourceType.getDisplayName() });
    if (mResourceType == ResourceType.DRAWABLE) {
      title = "Create New Icon...";
    }
    mNewButton.setText(title);
    
    mNewButton.addSelectionListener(new SelectionAdapter()
    {
      public void widgetSelected(SelectionEvent e)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd