Methods Summary |
---|
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 */);
}
}
|
protected org.eclipse.swt.widgets.Control | createDialogArea(org.eclipse.swt.widgets.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();
// create the "New Resource" button
createNewResButtons(top);
return top;
|
private void | createFilteredTree(org.eclipse.swt.widgets.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());
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 /* fullLevels */));
mTreeViewer.setInput(mResources);
|
private void | createNewResButtons(org.eclipse.swt.widgets.Composite top)Creates the "New Resource" button.
mNewResButton = new Button(top, SWT.NONE);
mNewResButton.addSelectionListener(new OnNewResButtonSelected());
updateNewResButton();
|
public java.lang.String | getCurrentResource()
return mCurrentResource;
|
private com.android.ide.eclipse.common.resources.ResourceType | getSelectedResourceType()Returns the {@link ResourceType} of the selected element, if any.
Returns null if nothing suitable is selected.
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 org.eclipse.jface.viewers.TreePath | getSelection()Returns the selected item in the tree as a {@link TreePath} object.
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;
|
protected void | handleDoubleClick()
if (validateCurrentSelection()) {
buttonPressed(IDialogConstants.OK_ID);
}
|
protected void | handleSelection()
validateCurrentSelection();
updateNewResButton();
|
public void | setCurrentResource(java.lang.String resource)
mCurrentResource = resource;
|
private void | setupInitialSelection()Sets up the initial selection.
This parses {@link #mCurrentResource} to find out the resource type and the resource name.
// 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);
}
}
}
|
private void | setupInitialSelection(com.android.ide.eclipse.common.resources.ResourceType resourceType, java.lang.String resourceName)Sets up the initial selection based on a {@link ResourceType} and a resource name.
// 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),
true /*reveal*/);
// 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),
true /*reveal*/);
mFilteredTree.getViewer().setExpandedState(resourceType, true /* expanded */);
|
private void | updateNewResButton()Updates the new res button when the list selection changes.
The name of the button changes depending on the resource.
ResourceType type = getSelectedResourceType();
// We only support adding new strings right now
mNewResButton.setEnabled(type == ResourceType.STRING);
String title = String.format("New %1$s...",
type == null ? "Resource" : type.getDisplayName());
mNewResButton.setText(title);
mNewResButton.pack();
|
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();
|