1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Bug #184457: tool chains filtering for templates.

This commit is contained in:
Oleg Krasilnikov 2007-05-04 08:37:08 +00:00
parent c7548e8313
commit 120967eec2

View file

@ -92,6 +92,7 @@ public class MBSWizardHandler extends CWizardHandler {
private EntryInfo entryInfo; private EntryInfo entryInfo;
protected static final class EntryInfo { protected static final class EntryInfo {
private SortedMap tcs;
private EntryDescriptor entryDescriptor; private EntryDescriptor entryDescriptor;
private Template template; private Template template;
private boolean initialized; private boolean initialized;
@ -102,8 +103,9 @@ public class MBSWizardHandler extends CWizardHandler {
private IWizardPage predatingPage; private IWizardPage predatingPage;
private IWizardPage followingPage; private IWizardPage followingPage;
public EntryInfo(EntryDescriptor dr){ public EntryInfo(EntryDescriptor dr, SortedMap _tcs){
entryDescriptor = dr; entryDescriptor = dr;
tcs = _tcs;
} }
public boolean isValid(){ public boolean isValid(){
@ -203,6 +205,59 @@ public class MBSWizardHandler extends CWizardHandler {
} }
return true; return true;
} }
/**
* Filters toolchains
*
* @return - set of compatible toolchain's IDs
*/
protected Set tc_filter() {
Set full = tcs.keySet();
if (entryDescriptor == null)
return full;
Set out = new LinkedHashSet(full.size());
Iterator it = full.iterator();
while (it.hasNext()) {
String s = (String)it.next();
if (isToolChainAcceptable(s))
out.add(s);
}
return out;
}
/**
* Checks whether given toolchain can be displayed
*
* @param tcId - toolchain _NAME_ to check
* @return - true if toolchain can be displayed
*/
public boolean isToolChainAcceptable(String tcId) {
if (template == null || template.getTemplateInfo() == null)
return true;
String[] ss = template.getTemplateInfo().getToolChainIds();
if (ss == null || ss.length == 0)
return true;
Object ob = tcs.get(tcId);
if (ob == null || !(ob instanceof IToolChain))
return false;
String id1 = ((IToolChain)ob).getId();
IToolChain sup = ((IToolChain)ob).getSuperClass();
String id2 = sup == null ? null : sup.getId();
for (int i=0; i<ss.length; i++) {
if ((ss[i] != null && ss[i].equals(id1)) ||
(ss[i] != null && ss[i].equals(id2)))
return true;
}
return false;
}
public int getToolChainsCount() {
return tc_filter().size();
}
} }
public MBSWizardHandler(IProjectType _pt, Composite p, IWizard w) { public MBSWizardHandler(IProjectType _pt, Composite p, IWizard w) {
@ -269,7 +324,8 @@ public class MBSWizardHandler extends CWizardHandler {
if (table == null) { if (table == null) {
table = new Table(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER); table = new Table(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
table.setToolTipText(tooltip); table.setToolTipText(tooltip);
Iterator it = tc_filter(full_tcs.keySet()).iterator(); if (entryInfo != null) {
Iterator it = entryInfo.tc_filter().iterator();
int counter = 0; int counter = 0;
int position = 0; int position = 0;
while (it.hasNext()) { while (it.hasNext()) {
@ -291,7 +347,7 @@ public class MBSWizardHandler extends CWizardHandler {
counter++; counter++;
} }
if (counter > 0) table.select(position); if (counter > 0) table.select(position);
}
table.addSelectionListener(new SelectionAdapter() { table.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
if (listener != null) if (listener != null)
@ -465,7 +521,10 @@ public class MBSWizardHandler extends CWizardHandler {
return ts; return ts;
} }
public int getToolChainsCount() { public int getToolChainsCount() {
return tc_filter(full_tcs.keySet()).size(); if (entryInfo == null)
return full_tcs.size();
else
return entryInfo.tc_filter().size();
} }
public String getPropertyId() { public String getPropertyId() {
return propertyId; return propertyId;
@ -535,79 +594,18 @@ public class MBSWizardHandler extends CWizardHandler {
} }
public boolean isApplicable(EntryDescriptor data) { public boolean isApplicable(EntryDescriptor data) {
EntryInfo info = new EntryInfo(data); EntryInfo info = new EntryInfo(data, full_tcs);
return info.isValid(); return info.isValid() && (info.getToolChainsCount() > 0);
} }
public void initialize(EntryDescriptor data) throws CoreException { public void initialize(EntryDescriptor data) throws CoreException {
EntryInfo info = new EntryInfo(data); EntryInfo info = new EntryInfo(data, full_tcs);
if(!info.isValid()) if(!info.isValid())
throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderUIPlugin.getUniqueIdentifier(), "inappropriate descriptor")); //$NON-NLS-1$ throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderUIPlugin.getUniqueIdentifier(), "inappropriate descriptor")); //$NON-NLS-1$
entryInfo = info; entryInfo = info;
} }
/**
* Filters toolchains according to entryDescriptor data
*
* @param full - full set of toolchain IDs
* @return - set of compatible toolchain's IDs
*
* Note that full_tcs map should remain unchanged
*/
protected Set tc_filter(Set full) {
if(entryInfo == null)
return full;
EntryDescriptor entryDescriptor = entryInfo.getDescriptor();
if (entryDescriptor == null)
return full;
Set out = new LinkedHashSet(full.size());
Iterator it = full.iterator();
while (it.hasNext()) {
String s = (String)it.next();
if (isToolChainAcceptable(s, entryDescriptor))
out.add(s);
}
return out;
}
/**
* Checks whether given toolchain can be displayed
*
* @param tcId - toolchain to check
* @param ed - Entry descriptor (Who Am I)
* @return - true if toolchain can be displayed
*/
protected boolean isToolChainAcceptable(String tcId, EntryDescriptor ed) {
// This method is temporary diabled
// (always returns true) until the
// end of discusion tracked by bug #184457
if (true) return true;
if (entryInfo == null || entryInfo.template == null ||
entryInfo.template.getTemplateInfo() == null)
return true;
String[] ss = entryInfo.template.getTemplateInfo().getToolChainIds();
if (ss == null && ss.length == 0)
return true;
Object ob = full_tcs.get(tcId);
if (ob == null || !(ob instanceof IToolChain))
return false;
String id1 = ((IToolChain)ob).getId();
IToolChain sup = ((IToolChain)ob).getSuperClass();
String id2 = sup == null ? null : sup.getId();
for (int i=0; i<ss.length; i++) {
if ((ss[i] != null && ss[i].equals(id1)) ||
(ss[i] != null && ss[i].equals(id2)))
return true;
}
return false;
}
/** /**
* Clones itself. * Clones itself.
*/ */