/** * Helper method that fills the values of the "root element" combo box based on the currently * selected type radio button. Also disables the combo is there's only one choice. Always select * the first root element for the given type. * * @param type The currently selected {@link TypeInfo}, or null */ private void updateRootCombo(TypeInfo type) { IBaseLabelProvider labelProvider = new ColumnLabelProvider() { @Override public Image getImage(Object element) { return IconFactory.getInstance().getIcon(element.toString()); } }; mRootTableViewer.setContentProvider(new ArrayContentProvider()); mRootTableViewer.setLabelProvider(labelProvider); if (type != null) { // get the list of roots. The list can be empty but not null. ArrayList<String> roots = type.getRoots(); mRootTableViewer.setInput(roots.toArray()); int index = 0; // default is to select the first one String defaultRoot = type.getDefaultRoot(mValues.project); if (defaultRoot != null) { index = roots.indexOf(defaultRoot); } mRootTable.select(index < 0 ? 0 : index); mRootTable.showSelection(); } }
/** Initialize the root values of the type infos based on the current framework values. */ private void initializeRootValues() { IProject project = mValues.project; for (TypeInfo type : sTypes) { // Clear all the roots for this type ArrayList<String> roots = type.getRoots(); if (roots.size() > 0) { roots.clear(); } // depending of the type of the seed, initialize the root in different ways Object rootSeed = type.getRootSeed(); if (rootSeed instanceof String) { // The seed is a single string, Add it as-is. roots.add((String) rootSeed); } else if (rootSeed instanceof String[]) { // The seed is an array of strings. Add them as-is. for (String value : (String[]) rootSeed) { roots.add(value); } } else if (rootSeed instanceof Integer && project != null) { // The seed is a descriptor reference defined in AndroidTargetData.DESCRIPTOR_* // In this case add all the children element descriptors defined, recursively, // and avoid infinite recursion by keeping track of what has already been added. // Note: if project is null, the root list will be empty since it has been // cleared above. // get the AndroidTargetData from the project IAndroidTarget target = null; AndroidTargetData data = null; target = Sdk.getCurrent().getTarget(project); if (target == null) { // A project should have a target. The target can be missing if the project // is an old project for which a target hasn't been affected or if the // target no longer exists in this SDK. Simply log the error and dismiss. AdtPlugin.log( IStatus.INFO, "NewXmlFile wizard: no platform target for project %s", //$NON-NLS-1$ project.getName()); continue; } else { data = Sdk.getCurrent().getTargetData(target); if (data == null) { // We should have both a target and its data. // However if the wizard is invoked whilst the platform is still being // loaded we can end up in a weird case where we have a target but it // doesn't have any data yet. // Lets log a warning and silently ignore this root. AdtPlugin.log( IStatus.INFO, "NewXmlFile wizard: no data for target %s, project %s", //$NON-NLS-1$ target.getName(), project.getName()); continue; } } IDescriptorProvider provider = data.getDescriptorProvider((Integer) rootSeed); ElementDescriptor descriptor = provider.getDescriptor(); if (descriptor != null) { HashSet<ElementDescriptor> visited = new HashSet<ElementDescriptor>(); initRootElementDescriptor(roots, descriptor, visited); } // Sort alphabetically. Collections.sort(roots); } } }