1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2013-06-08 13:46:48 -07:00
parent 06e1b830a8
commit eb081d7f1f
3 changed files with 411 additions and 415 deletions

View file

@ -6,10 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
* Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.dom.ILinkage;
@ -26,5 +25,5 @@ public interface IIndexLinkage extends ILinkage {
* Empty IIndexLinkage array constant
* @since 4.0.1
*/
IIndexLinkage[] EMPTY_INDEX_LINKAGE_ARRAY= new IIndexLinkage[0];
IIndexLinkage[] EMPTY_INDEX_LINKAGE_ARRAY= {};
}

View file

@ -53,7 +53,7 @@ import org.eclipse.core.runtime.Assert;
/**
* Specialization of a class.
*/
public class CPPClassSpecialization extends CPPSpecialization
public class CPPClassSpecialization extends CPPSpecialization
implements ICPPClassSpecialization, ICPPInternalClassTypeMixinHost {
public static class RecursionResolvingBinding extends ProblemBinding implements ICPPMember, IRecursionResolvingBinding {
@ -156,34 +156,34 @@ public class CPPClassSpecialization extends CPPSpecialization
public ICPPClassType getSpecializedBinding() {
return (ICPPClassType) super.getSpecializedBinding();
}
@Override
public IBinding specializeMember(IBinding original) {
return specializeMember(original, null);
}
@Override
public IBinding specializeMember(IBinding original, IASTNode point) {
public IBinding specializeMember(IBinding original, IASTNode point) {
Set<IBinding> set;
synchronized (this) {
IBinding result= (IBinding) specializationMap.get(original);
if (result != null)
if (result != null)
return result;
set= fInProgress.get();
if (set == null) {
set= new HashSet<IBinding>();
fInProgress.set(set);
}
if (!set.add(original))
}
if (!set.add(original))
return RecursionResolvingBinding.createFor(original, point);
}
IBinding result= CPPTemplates.createSpecialization(this, original, point);
set.remove(original);
synchronized (this) {
IBinding concurrent= (IBinding) specializationMap.get(original);
if (concurrent != null)
if (concurrent != null)
return concurrent;
if (specializationMap == ObjectMap.EMPTY_MAP)
specializationMap = new ObjectMap(2);
@ -191,7 +191,7 @@ public class CPPClassSpecialization extends CPPSpecialization
return result;
}
}
@Override
public void checkForDefinition() {
// Ambiguity resolution ensures that declarations and definitions are resolved.
@ -209,7 +209,7 @@ public class CPPClassSpecialization extends CPPSpecialization
}
return null;
}
@Override
public ICPPBase[] getBases() {
CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$
@ -284,7 +284,7 @@ public class CPPClassSpecialization extends CPPSpecialization
return scope.getFriends(point);
}
@Override
public ICPPClassType[] getNestedClasses() {
CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work.")); //$NON-NLS-1$
@ -345,7 +345,7 @@ public class CPPClassSpecialization extends CPPSpecialization
public int getKey() {
if (getDefinition() != null)
return getCompositeTypeSpecifier().getKey();
return getSpecializedBinding().getKey();
}
@ -357,24 +357,24 @@ public class CPPClassSpecialization extends CPPSpecialization
final ICPPClassScope specScope= getSpecializationScope();
if (specScope != null)
return specScope;
final ICPPASTCompositeTypeSpecifier typeSpecifier = getCompositeTypeSpecifier();
if (typeSpecifier != null)
return typeSpecifier.getScope();
return null;
}
protected ICPPClassSpecializationScope getSpecializationScope() {
checkForDefinition();
if (getDefinition() != null)
return null;
// Implicit specialization: must specialize bindings in scope.
if (specScope == null) {
specScope = new CPPClassSpecializationScope(this);
}
return specScope;
return specScope;
}
@Override
@ -397,10 +397,10 @@ public class CPPClassSpecialization extends CPPSpecialization
@Override
public boolean isAnonymous() {
if (getNameCharArray().length > 0)
if (getNameCharArray().length > 0)
return false;
ICPPASTCompositeTypeSpecifier spec= getCompositeTypeSpecifier();
ICPPASTCompositeTypeSpecifier spec= getCompositeTypeSpecifier();
if (spec == null) {
return getSpecializedBinding().isAnonymous();
}
@ -416,23 +416,23 @@ public class CPPClassSpecialization extends CPPSpecialization
public static boolean isSameClassSpecialization(ICPPClassSpecialization t1, ICPPClassSpecialization t2) {
// Exclude class template specialization or class instance.
if (t2 instanceof ICPPTemplateInstance || t2 instanceof ICPPTemplateDefinition ||
if (t2 instanceof ICPPTemplateInstance || t2 instanceof ICPPTemplateDefinition ||
t2 instanceof IProblemBinding) {
return false;
}
if (t1.getKey() != t2.getKey())
if (t1.getKey() != t2.getKey())
return false;
if (!CharArrayUtils.equals(t1.getNameCharArray(), t2.getNameCharArray()))
return false;
// The argument map is not significant for comparing specializations, the map is
// determined by the owner of the specialization. This is different for instances,
// which have a separate implementation for isSameType().
final IBinding owner1= t1.getOwner();
final IBinding owner2= t2.getOwner();
// For a specialization that is not an instance the owner has to be a class-type.
if (!(owner1 instanceof ICPPClassType) || !(owner2 instanceof ICPPClassType))
return false;

View file

@ -10,7 +10,8 @@
* IBM Corporation
*******************************************************************************/
package org.eclipse.cdt.ui.wizards;
import java.net.URI;
import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ -53,446 +54,442 @@ import org.eclipse.cdt.ui.newui.PageLayout;
import org.eclipse.cdt.internal.ui.newui.Messages;
public class CDTMainWizardPage extends WizardNewProjectCreationPage implements IWizardItemsListListener {
private static final Image IMG_CATEGORY = CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_SEARCHFOLDER);
private static final Image IMG_ITEM = CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_VARIABLE);
public class CDTMainWizardPage extends WizardNewProjectCreationPage implements IWizardItemsListListener {
private static final Image IMG_CATEGORY = CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_SEARCHFOLDER);
private static final Image IMG_ITEM = CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_VARIABLE);
public static final String PAGE_ID = "org.eclipse.cdt.managedbuilder.ui.wizard.NewModelProjectWizardPage"; //$NON-NLS-1$
public static final String PAGE_ID = "org.eclipse.cdt.managedbuilder.ui.wizard.NewModelProjectWizardPage"; //$NON-NLS-1$
private static final String EXTENSION_POINT_ID = "org.eclipse.cdt.ui.CDTWizard"; //$NON-NLS-1$
private static final String ELEMENT_NAME = "wizard"; //$NON-NLS-1$
private static final String CLASS_NAME = "class"; //$NON-NLS-1$
public static final String DESC = "EntryDescriptor"; //$NON-NLS-1$
private static final String EXTENSION_POINT_ID = "org.eclipse.cdt.ui.CDTWizard"; //$NON-NLS-1$
private static final String ELEMENT_NAME = "wizard"; //$NON-NLS-1$
private static final String CLASS_NAME = "class"; //$NON-NLS-1$
public static final String DESC = "EntryDescriptor"; //$NON-NLS-1$
// widgets
private Tree tree;
private Composite right;
private Button show_sup;
private Label right_label;
// Widgets
private Tree tree;
private Composite right;
private Button showSup;
private Label rightLabel;
public CWizardHandler h_selected = null;
private Label categorySelectedLabel;
public CWizardHandler h_selected;
private Label categorySelectedLabel;
/**
* Creates a new project creation wizard page.
*
* @param pageName the name of this page
*/
public CDTMainWizardPage(String pageName) {
super(pageName);
setPageComplete(false);
}
/**
* Creates a new project creation wizard page.
*
* @param pageName the name of this page
*/
public CDTMainWizardPage(String pageName) {
super(pageName);
setPageComplete(false);
}
/** (non-Javadoc)
* Method declared on IDialogPage.
*/
@Override
public void createControl(Composite parent) {
super.createControl(parent);
@Override
public void createControl(Composite parent) {
super.createControl(parent);
createDynamicGroup((Composite)getControl());
switchTo(updateData(tree, right, show_sup, CDTMainWizardPage.this, getWizard()),
getDescriptor(tree));
createDynamicGroup((Composite)getControl());
switchTo(updateData(tree, right, showSup, CDTMainWizardPage.this, getWizard()),
getDescriptor(tree));
setPageComplete(validatePage());
setErrorMessage(null);
setMessage(null);
}
setPageComplete(validatePage());
setErrorMessage(null);
setMessage(null);
}
private void createDynamicGroup(Composite parent) {
Composite c = new Composite(parent, SWT.NONE);
c.setLayoutData(new GridData(GridData.FILL_BOTH));
c.setLayout(new GridLayout(2, true));
private void createDynamicGroup(Composite parent) {
Composite c = new Composite(parent, SWT.NONE);
c.setLayoutData(new GridData(GridData.FILL_BOTH));
c.setLayout(new GridLayout(2, true));
Label l1 = new Label(c, SWT.NONE);
l1.setText(Messages.CMainWizardPage_0);
l1.setFont(parent.getFont());
l1.setLayoutData(new GridData(GridData.BEGINNING));
Label l1 = new Label(c, SWT.NONE);
l1.setText(Messages.CMainWizardPage_0);
l1.setFont(parent.getFont());
l1.setLayoutData(new GridData(GridData.BEGINNING));
right_label = new Label(c, SWT.NONE);
right_label.setFont(parent.getFont());
right_label.setLayoutData(new GridData(GridData.BEGINNING));
rightLabel = new Label(c, SWT.NONE);
rightLabel.setFont(parent.getFont());
rightLabel.setLayoutData(new GridData(GridData.BEGINNING));
tree = new Tree(c, SWT.SINGLE | SWT.BORDER);
tree.setLayoutData(new GridData(GridData.FILL_BOTH));
tree.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TreeItem[] tis = tree.getSelection();
if (tis == null || tis.length == 0) return;
switchTo((CWizardHandler)tis[0].getData(), (EntryDescriptor)tis[0].getData(DESC));
setPageComplete(validatePage());
}});
tree.getAccessible().addAccessibleListener(
new AccessibleAdapter() {
@Override
public void getName(AccessibleEvent e) {
for (int i = 0; i < tree.getItemCount(); i++) {
if (tree.getItem(i).getText().equals(e.result))
return;
}
e.result = Messages.CMainWizardPage_0;
}
}
);
right = new Composite(c, SWT.NONE);
right.setLayoutData(new GridData(GridData.FILL_BOTH));
right.setLayout(new PageLayout());
tree = new Tree(c, SWT.SINGLE | SWT.BORDER);
tree.setLayoutData(new GridData(GridData.FILL_BOTH));
tree.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TreeItem[] tis = tree.getSelection();
if (tis == null || tis.length == 0) return;
switchTo((CWizardHandler)tis[0].getData(), (EntryDescriptor)tis[0].getData(DESC));
setPageComplete(validatePage());
}});
tree.getAccessible().addAccessibleListener(new AccessibleAdapter() {
@Override
public void getName(AccessibleEvent e) {
for (int i = 0; i < tree.getItemCount(); i++) {
if (tree.getItem(i).getText().equals(e.result))
return;
}
e.result = Messages.CMainWizardPage_0;
}});
right = new Composite(c, SWT.NONE);
right.setLayoutData(new GridData(GridData.FILL_BOTH));
right.setLayout(new PageLayout());
show_sup = new Button(c, SWT.CHECK);
show_sup.setText(Messages.CMainWizardPage_1);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
show_sup.setLayoutData(gd);
show_sup.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (h_selected != null)
h_selected.setSupportedOnly(show_sup.getSelection());
switchTo(updateData(tree, right, show_sup, CDTMainWizardPage.this, getWizard()),
getDescriptor(tree));
}} );
showSup = new Button(c, SWT.CHECK);
showSup.setText(Messages.CMainWizardPage_1);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
showSup.setLayoutData(gd);
showSup.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (h_selected != null)
h_selected.setSupportedOnly(showSup.getSelection());
switchTo(updateData(tree, right, showSup, CDTMainWizardPage.this, getWizard()),
getDescriptor(tree));
}});
// restore settings from preferences
show_sup.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOSUPP));
}
// restore settings from preferences
showSup.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOSUPP));
}
@Override
public IWizardPage getNextPage() {
return (h_selected == null) ? null : h_selected.getSpecificPage();
}
@Override
public IWizardPage getNextPage() {
return (h_selected == null) ? null : h_selected.getSpecificPage();
}
public URI getProjectLocation() {
return useDefaults() ? null : getLocationURI();
}
public URI getProjectLocation() {
return useDefaults() ? null : getLocationURI();
}
/**
* Returns whether this page's controls currently all contain valid
* values.
*
* @return <code>true</code> if all controls are valid, and
* <code>false</code> if at least one is invalid
*/
@Override
protected boolean validatePage() {
setMessage(null);
if (!super.validatePage())
return false;
/**
* Returns whether this page's controls currently all contain valid
* values.
*
* @return <code>true</code> if all controls are valid, and
* <code>false</code> if at least one is invalid
*/
@Override
protected boolean validatePage() {
setMessage(null);
if (!super.validatePage())
return false;
if (getProjectName().indexOf('#') >= 0) {
setErrorMessage(Messages.CDTMainWizardPage_0);
return false;
}
if (getProjectName().indexOf('#') >= 0) {
setErrorMessage(Messages.CDTMainWizardPage_0);
return false;
}
boolean bad = true; // should we treat existing project as error
boolean bad = true; // should we treat existing project as error
IProject handle = getProjectHandle();
if (handle.exists()) {
if (getWizard() instanceof IWizardWithMemory) {
IWizardWithMemory w = (IWizardWithMemory)getWizard();
if (w.getLastProjectName() != null && w.getLastProjectName().equals(getProjectName()))
bad = false;
}
if (bad) {
setErrorMessage(Messages.CMainWizardPage_10);
return false;
}
}
IProject handle = getProjectHandle();
if (handle.exists()) {
if (getWizard() instanceof IWizardWithMemory) {
IWizardWithMemory w = (IWizardWithMemory)getWizard();
if (w.getLastProjectName() != null && w.getLastProjectName().equals(getProjectName()))
bad = false;
}
if (bad) {
setErrorMessage(Messages.CMainWizardPage_10);
return false;
}
}
if (bad) { // skip this check if project already created
try {
IFileStore fs;
URI p = getProjectLocation();
if (p == null) {
fs = EFS.getStore(ResourcesPlugin.getWorkspace().getRoot().getLocationURI());
fs = fs.getChild(getProjectName());
} else
fs = EFS.getStore(p);
IFileInfo f = fs.fetchInfo();
if (f.exists()) {
if (f.isDirectory()) {
if (f.getAttribute(EFS.ATTRIBUTE_READ_ONLY)) {
setErrorMessage(Messages.CMainWizardPage_DirReadOnlyError);
return false;
}
else
setMessage(Messages.CMainWizardPage_7, IMessageProvider.WARNING);
} else {
setErrorMessage(Messages.CMainWizardPage_6);
return false;
}
}
} catch (CoreException e) {
CUIPlugin.log(e.getStatus());
}
}
if (!useDefaults()) {
IStatus locationStatus = ResourcesPlugin.getWorkspace().validateProjectLocationURI(handle,
getLocationURI());
if (!locationStatus.isOK()) {
setErrorMessage(locationStatus.getMessage());
return false;
}
}
if (tree.getItemCount() == 0) {
setErrorMessage(Messages.CMainWizardPage_3);
return false;
}
// it is not an error, but we cannot continue
if (h_selected == null) {
setErrorMessage(null);
return false;
}
String s = h_selected.getErrorMessage();
if (s != null) {
setErrorMessage(s);
return false;
}
setErrorMessage(null);
return true;
}
/**
*
* @param tree
* @param right
* @param show_sup
* @param ls
* @param wizard
* @return : selected Wizard Handler.
*/
public static CWizardHandler updateData(Tree tree, Composite right, Button show_sup, IWizardItemsListListener ls, IWizard wizard) {
// remember selected item
TreeItem[] selection = tree.getSelection();
TreeItem selectedItem = selection.length>0 ? selection[0] : null;
String savedLabel = selectedItem!=null ? selectedItem.getText() : null;
String savedParentLabel = getParentText(selectedItem);
tree.removeAll();
IExtensionPoint extensionPoint =
Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_POINT_ID);
if (extensionPoint == null) return null;
IExtension[] extensions = extensionPoint.getExtensions();
if (extensions == null) return null;
List<EntryDescriptor> items = new ArrayList<EntryDescriptor>();
for (int i = 0; i < extensions.length; ++i) {
IConfigurationElement[] elements = extensions[i].getConfigurationElements();
for (IConfigurationElement element : elements) {
if (element.getName().equals(ELEMENT_NAME)) {
CNewWizard w = null;
try {
w = (CNewWizard) element.createExecutableExtension(CLASS_NAME);
} catch (CoreException e) {
System.out.println(Messages.CMainWizardPage_5 + e.getLocalizedMessage());
return null;
if (bad) { // Skip this check if project already created
try {
IFileStore fs;
URI p = getProjectLocation();
if (p == null) {
fs = EFS.getStore(ResourcesPlugin.getWorkspace().getRoot().getLocationURI());
fs = fs.getChild(getProjectName());
} else
fs = EFS.getStore(p);
IFileInfo f = fs.fetchInfo();
if (f.exists()) {
if (f.isDirectory()) {
if (f.getAttribute(EFS.ATTRIBUTE_READ_ONLY)) {
setErrorMessage(Messages.CMainWizardPage_DirReadOnlyError);
return false;
}
if (w == null) return null;
w.setDependentControl(right, ls);
for (EntryDescriptor ed : w.createItems(show_sup.getSelection(), wizard))
items.add(ed);
else
setMessage(Messages.CMainWizardPage_7, IMessageProvider.WARNING);
} else {
setErrorMessage(Messages.CMainWizardPage_6);
return false;
}
}
} catch (CoreException e) {
CUIPlugin.log(e.getStatus());
}
// If there is a EntryDescriptor which is default for category, make sure it
// is in the front of the list.
for (int i = 0; i < items.size(); ++i)
{
EntryDescriptor ed = items.get(i);
if (ed.isDefaultForCategory())
{
items.remove(i);
items.add(0, ed);
break;
}
}
if (!useDefaults()) {
IStatus locationStatus =
ResourcesPlugin.getWorkspace().validateProjectLocationURI(handle, getLocationURI());
if (!locationStatus.isOK()) {
setErrorMessage(locationStatus.getMessage());
return false;
}
}
// bug # 211935 : allow items filtering.
if (ls != null) // NULL means call from prefs
items = ls.filterItems(items);
addItemsToTree(tree, items);
if (tree.getItemCount() == 0) {
setErrorMessage(Messages.CMainWizardPage_3);
return false;
}
if (tree.getItemCount() > 0) {
TreeItem target = null;
// try to search item which was selected before
if (savedLabel != null) {
target = findItem(tree, savedLabel, savedParentLabel);
}
if (target == null) {
// Default selection associated with "org.eclipse.cdt.build.core.buildArtefactType.exe" project type
target = findItem(tree, Messages.CDTMainWizardPage_DefaultProjectType, Messages.CDTMainWizardPage_DefaultProjectCategory);
if (target == null) {
CUIPlugin.log(new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID, "Default project not found in New C/C++ Project Wizard")); //$NON-NLS-1$
// it is not an error, but we cannot continue
if (h_selected == null) {
setErrorMessage(null);
return false;
}
String s = h_selected.getErrorMessage();
if (s != null) {
setErrorMessage(s);
return false;
}
setErrorMessage(null);
return true;
}
/**
*
* @param tree
* @param right
* @param show_sup
* @param ls
* @param wizard
* @return : selected Wizard Handler.
*/
public static CWizardHandler updateData(Tree tree, Composite right, Button show_sup,
IWizardItemsListListener ls, IWizard wizard) {
// Remember selected item
TreeItem[] selection = tree.getSelection();
TreeItem selectedItem = selection.length > 0 ? selection[0] : null;
String savedLabel = selectedItem != null ? selectedItem.getText() : null;
String savedParentLabel = getParentText(selectedItem);
tree.removeAll();
IExtensionPoint extensionPoint =
Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_POINT_ID);
if (extensionPoint == null) return null;
IExtension[] extensions = extensionPoint.getExtensions();
if (extensions == null) return null;
List<EntryDescriptor> items = new ArrayList<EntryDescriptor>();
for (int i = 0; i < extensions.length; ++i) {
IConfigurationElement[] elements = extensions[i].getConfigurationElements();
for (IConfigurationElement element : elements) {
if (element.getName().equals(ELEMENT_NAME)) {
CNewWizard w = null;
try {
w = (CNewWizard) element.createExecutableExtension(CLASS_NAME);
} catch (CoreException e) {
System.out.println(Messages.CMainWizardPage_5 + e.getLocalizedMessage());
return null;
}
if (w == null)
return null;
w.setDependentControl(right, ls);
for (EntryDescriptor ed : w.createItems(show_sup.getSelection(), wizard))
items.add(ed);
}
}
}
// If there is a EntryDescriptor which is default for category, make sure it
// is in the front of the list.
for (int i = 0; i < items.size(); ++i) {
EntryDescriptor ed = items.get(i);
if (ed.isDefaultForCategory()) {
items.remove(i);
items.add(0, ed);
break;
}
}
// bug # 211935 : allow items filtering.
if (ls != null) // NULL means call from prefs
items = ls.filterItems(items);
addItemsToTree(tree, items);
if (tree.getItemCount() > 0) {
TreeItem target = null;
// Try to search item which was selected before
if (savedLabel != null) {
target = findItem(tree, savedLabel, savedParentLabel);
}
if (target == null) {
// Default selection associated with "org.eclipse.cdt.build.core.buildArtefactType.exe" project type
target = findItem(tree, Messages.CDTMainWizardPage_DefaultProjectType,
Messages.CDTMainWizardPage_DefaultProjectCategory);
if (target == null) {
target = tree.getItem(0);
if (target.getItemCount() != 0)
target = target.getItem(0);
CUIPlugin.log(new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID,
"Default project not found in New C/C++ Project Wizard")); //$NON-NLS-1$
}
tree.setSelection(target);
return (CWizardHandler)target.getData();
}
return null;
}
private static String getParentText(TreeItem item) {
if (item==null || item.getParentItem()==null)
return ""; //$NON-NLS-1$
return item.getParentItem().getText();
}
private static TreeItem findItem(Tree tree, String label, String parentLabel) {
for (TreeItem item : tree.getItems()) {
TreeItem foundItem = findTreeItem(item, label, parentLabel);
if (foundItem!=null)
return foundItem;
if (target == null) {
target = tree.getItem(0);
if (target.getItemCount() != 0)
target = target.getItem(0);
}
return null;
tree.setSelection(target);
return (CWizardHandler)target.getData();
}
return null;
}
private static TreeItem findTreeItem(TreeItem item, String label, String parentLabel) {
if (item.getText().equals(label) && getParentText(item).equals(parentLabel))
return item;
private static String getParentText(TreeItem item) {
if (item == null || item.getParentItem() == null)
return ""; //$NON-NLS-1$
return item.getParentItem().getText();
}
for (TreeItem child : item.getItems()) {
TreeItem foundItem = findTreeItem(child, label, parentLabel);
if (foundItem!=null)
return foundItem;
}
return null;
private static TreeItem findItem(Tree tree, String label, String parentLabel) {
for (TreeItem item : tree.getItems()) {
TreeItem foundItem = findTreeItem(item, label, parentLabel);
if (foundItem!=null)
return foundItem;
}
return null;
}
private static void addItemsToTree(Tree tree, List<EntryDescriptor> items) {
private static TreeItem findTreeItem(TreeItem item, String label, String parentLabel) {
if (item.getText().equals(label) && getParentText(item).equals(parentLabel))
return item;
for (TreeItem child : item.getItems()) {
TreeItem foundItem = findTreeItem(child, label, parentLabel);
if (foundItem!=null)
return foundItem;
}
return null;
}
private static void addItemsToTree(Tree tree, List<EntryDescriptor> items) {
// Sorting is disabled because of users requests
// Collections.sort(items, CDTListComparator.getInstance());
ArrayList<TreeItem> placedTreeItemsList = new ArrayList<TreeItem>(items.size());
ArrayList<EntryDescriptor> placedEntryDescriptorsList = new ArrayList<EntryDescriptor>(items.size());
for (EntryDescriptor wd : items) {
if (wd.getParentId() == null) {
wd.setPath(wd.getId());
TreeItem ti = new TreeItem(tree, SWT.NONE);
ti.setText(TextProcessor.process(wd.getName()));
ti.setData(wd.getHandler());
ti.setData(DESC, wd);
ti.setImage(calcImage(wd));
placedTreeItemsList.add(ti);
placedEntryDescriptorsList.add(wd);
}
ArrayList<TreeItem> placedTreeItemsList = new ArrayList<TreeItem>(items.size());
ArrayList<EntryDescriptor> placedEntryDescriptorsList = new ArrayList<EntryDescriptor>(items.size());
for (EntryDescriptor wd : items) {
if (wd.getParentId() == null) {
wd.setPath(wd.getId());
TreeItem ti = new TreeItem(tree, SWT.NONE);
ti.setText(TextProcessor.process(wd.getName()));
ti.setData(wd.getHandler());
ti.setData(DESC, wd);
ti.setImage(calcImage(wd));
placedTreeItemsList.add(ti);
placedEntryDescriptorsList.add(wd);
}
while(true) {
boolean found = false;
Iterator<EntryDescriptor> it2 = items.iterator();
while (it2.hasNext()) {
EntryDescriptor wd1 = it2.next();
if (wd1.getParentId() == null) continue;
for (int i = 0; i< placedEntryDescriptorsList.size(); i++) {
EntryDescriptor wd2 = placedEntryDescriptorsList.get(i);
if (wd2.getId().equals(wd1.getParentId())) {
found = true;
wd1.setParentId(null);
CWizardHandler h = wd2.getHandler();
/* If neither wd1 itself, nor its parent (wd2) have a handler
* associated with them, and the item is not a category,
* then skip it. If it's category, then it's possible that
* children will have a handler associated with them.
*/
if (h == null && wd1.getHandler() == null && !wd1.isCategory())
break;
wd1.setPath(wd2.getPath() + "/" + wd1.getId()); //$NON-NLS-1$
wd1.setParent(wd2);
if (h != null) {
if (wd1.getHandler() == null && !wd1.isCategory())
wd1.setHandler((CWizardHandler)h.clone());
if (!h.isApplicable(wd1))
break;
}
TreeItem p = placedTreeItemsList.get(i);
TreeItem ti = new TreeItem(p, SWT.NONE);
ti.setText(wd1.getName());
ti.setData(wd1.getHandler());
ti.setData(DESC, wd1);
ti.setImage(calcImage(wd1));
placedTreeItemsList.add(ti);
placedEntryDescriptorsList.add(wd1);
}
while (true) {
boolean found = false;
Iterator<EntryDescriptor> it2 = items.iterator();
while (it2.hasNext()) {
EntryDescriptor wd1 = it2.next();
if (wd1.getParentId() == null) continue;
for (int i = 0; i < placedEntryDescriptorsList.size(); i++) {
EntryDescriptor wd2 = placedEntryDescriptorsList.get(i);
if (wd2.getId().equals(wd1.getParentId())) {
found = true;
wd1.setParentId(null);
CWizardHandler h = wd2.getHandler();
/* If neither wd1 itself, nor its parent (wd2) have a handler
* associated with them, and the item is not a category,
* then skip it. If it's category, then it's possible that
* children will have a handler associated with them.
*/
if (h == null && wd1.getHandler() == null && !wd1.isCategory())
break;
wd1.setPath(wd2.getPath() + "/" + wd1.getId()); //$NON-NLS-1$
wd1.setParent(wd2);
if (h != null) {
if (wd1.getHandler() == null && !wd1.isCategory())
wd1.setHandler((CWizardHandler)h.clone());
if (!h.isApplicable(wd1))
break;
}
TreeItem p = placedTreeItemsList.get(i);
TreeItem ti = new TreeItem(p, SWT.NONE);
ti.setText(wd1.getName());
ti.setData(wd1.getHandler());
ti.setData(DESC, wd1);
ti.setImage(calcImage(wd1));
placedTreeItemsList.add(ti);
placedEntryDescriptorsList.add(wd1);
break;
}
}
// repeat iterations until all items are placed.
if (!found) break;
}
// orphan elements (with not-existing parentId) are ignored
// repeat iterations until all items are placed.
if (!found) break;
}
// orphan elements (with not-existing parentId) are ignored
}
private void switchTo(CWizardHandler h, EntryDescriptor ed) {
if (h == null)
h = ed.getHandler();
if (ed.isCategory())
h = null;
try {
if (h != null)
h.initialize(ed);
} catch (CoreException e) {
h = null;
}
if (h_selected != null)
h_selected.handleUnSelection();
h_selected = h;
if (h == null) {
if (ed.isCategory()) {
if (categorySelectedLabel == null) {
categorySelectedLabel = new Label(right, SWT.WRAP);
categorySelectedLabel.setText(
Messages.CDTMainWizardPage_1);
right.layout();
}
categorySelectedLabel.setVisible(true);
private void switchTo(CWizardHandler h, EntryDescriptor ed) {
if (h == null)
h = ed.getHandler();
if (ed.isCategory())
h = null;
try {
if (h != null)
h.initialize(ed);
} catch (CoreException e) {
h = null;
}
if (h_selected != null)
h_selected.handleUnSelection();
h_selected = h;
if (h == null) {
if (ed.isCategory()) {
if (categorySelectedLabel == null) {
categorySelectedLabel = new Label(right, SWT.WRAP);
categorySelectedLabel.setText(Messages.CDTMainWizardPage_1);
right.layout();
}
return;
categorySelectedLabel.setVisible(true);
}
right_label.setText(h_selected.getHeader());
if (categorySelectedLabel != null)
categorySelectedLabel.setVisible(false);
h_selected.handleSelection();
h_selected.setSupportedOnly(show_sup.getSelection());
return;
}
rightLabel.setText(h_selected.getHeader());
if (categorySelectedLabel != null)
categorySelectedLabel.setVisible(false);
h_selected.handleSelection();
h_selected.setSupportedOnly(showSup.getSelection());
}
public static EntryDescriptor getDescriptor(Tree _tree) {
TreeItem[] sel = _tree.getSelection();
if (sel == null || sel.length == 0)
return null;
return (EntryDescriptor)sel[0].getData(DESC);
}
public static EntryDescriptor getDescriptor(Tree tree) {
TreeItem[] sel = tree.getSelection();
if (sel == null || sel.length == 0)
return null;
return (EntryDescriptor)sel[0].getData(DESC);
}
@Override
public void toolChainListChanged(int count) {
setPageComplete(validatePage());
getWizard().getContainer().updateButtons();
}
@Override
public void toolChainListChanged(int count) {
setPageComplete(validatePage());
getWizard().getContainer().updateButtons();
}
@Override
public boolean isCurrent() { return isCurrentPage(); }
@Override
public boolean isCurrent() {
return isCurrentPage();
}
private static Image calcImage(EntryDescriptor ed) {
if (ed.getImage() != null) return ed.getImage();
if (ed.isCategory()) return IMG_CATEGORY;
return IMG_ITEM;
}
private static Image calcImage(EntryDescriptor ed) {
if (ed.getImage() != null) return ed.getImage();
if (ed.isCategory()) return IMG_CATEGORY;
return IMG_ITEM;
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List filterItems(List items) {
return items;
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List filterItems(List items) {
return items;
}
}