mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 11:25:35 +02:00
Bug #160012: New Project Wizard changed to support templates
This commit is contained in:
parent
3a6af038ff
commit
e085fd2c3e
12 changed files with 297 additions and 138 deletions
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.managedbuilder.ui.tests;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.managedbuilder.core.IProjectType;
|
||||
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
|
||||
import org.eclipse.cdt.ui.wizards.CDTMainWizardPage;
|
||||
|
@ -49,14 +50,14 @@ public class TestCProjectPlatformPage extends TestCase implements IWizardItemsLi
|
|||
page = null;
|
||||
wizard = null;
|
||||
}
|
||||
|
||||
ArrayUtil x;
|
||||
|
||||
// testing methods
|
||||
//////////////////
|
||||
|
||||
/* Test the new page, set selection, create page lifecycle. */
|
||||
public void testHandler1() throws Exception {
|
||||
CWizardHandler h = new CWizardHandler(getShell(), "Head", "Name", null);
|
||||
CWizardHandler h = new CWizardHandler(getShell(), "Head", "Name");
|
||||
assertNotNull(h);
|
||||
/*
|
||||
IProjectType pt = new TestProjectType();
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.SortedMap;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyManager;
|
||||
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyType;
|
||||
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyValue;
|
||||
|
@ -24,17 +25,20 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
|||
import org.eclipse.cdt.managedbuilder.ui.properties.Messages;
|
||||
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
|
||||
import org.eclipse.cdt.ui.wizards.ICWizardHandler;
|
||||
import org.eclipse.cdt.ui.wizards.WizardItemData;
|
||||
import org.eclipse.cdt.ui.wizards.EntryDescriptor;
|
||||
import org.eclipse.jface.wizard.IWizard;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class CNewWizard extends AbstractCWizard {
|
||||
private static final Image IMG = CPluginImages.get(CPluginImages.IMG_OBJS_CONTAINER);
|
||||
private static final String OTHERS_LABEL = Messages.getString("CNewWizard.0"); //$NON-NLS-1$
|
||||
/**
|
||||
* Creates and returns an array of items to be displayed
|
||||
*/
|
||||
public WizardItemData[] createItems(boolean supportedOnly, IWizard wizard) {
|
||||
public EntryDescriptor[] createItems(boolean supportedOnly, IWizard wizard) {
|
||||
IBuildPropertyManager bpm = ManagedBuildManager.getBuildPropertyManager();
|
||||
IBuildPropertyType bpt = bpm.getPropertyType(ICWizardHandler.ARTIFACT);
|
||||
IBuildPropertyValue[] vs = bpt.getSupportedValues();
|
||||
|
@ -44,23 +48,17 @@ public class CNewWizard extends AbstractCWizard {
|
|||
for (int i=0; i<vs.length; i++) {
|
||||
IToolChain[] tcs = ManagedBuildManager.getExtensionsToolChains(ICWizardHandler.ARTIFACT, vs[i].getId());
|
||||
if (tcs == null || tcs.length == 0) continue;
|
||||
MBSWizardHandler h = new MBSWizardHandler(vs[i], IMG1, parent, wizard);
|
||||
MBSWizardHandler h = new MBSWizardHandler(vs[i], parent, wizard);
|
||||
for (int j=0; j<tcs.length; j++) {
|
||||
if (!supportedOnly || isValid(tcs[j])) h.addTc(tcs[j]);
|
||||
}
|
||||
if (h.getToolChainsCount() > 0) {
|
||||
WizardItemData wd = new WizardItemData();
|
||||
wd.name = h.getName();
|
||||
wd.handler = h;
|
||||
wd.image = h.getIcon();
|
||||
wd.id = h.getName();
|
||||
wd.parentId = null;
|
||||
items.add(wd);
|
||||
items.add(new EntryDescriptor(vs[i].getId(), null, vs[i].getName(), true, h, null));
|
||||
}
|
||||
}
|
||||
|
||||
// old style project types
|
||||
WizardItemData oldsRoot = null;
|
||||
EntryDescriptor oldsRoot = null;
|
||||
SortedMap sm = ManagedBuildManager.getExtensionProjectTypeMap();
|
||||
Iterator it = sm.keySet().iterator();
|
||||
while(it.hasNext()) {
|
||||
|
@ -70,7 +68,7 @@ public class CNewWizard extends AbstractCWizard {
|
|||
if (supportedOnly && !pt.isSupported()) continue; // not supported
|
||||
String nattr = pt.getNameAttribute();
|
||||
if (nattr == null || nattr.length() == 0) continue; // new proj style
|
||||
MBSWizardHandler h = new MBSWizardHandler(pt.getName(), pt, IMG2, parent, wizard);
|
||||
MBSWizardHandler h = new MBSWizardHandler(pt, parent, wizard);
|
||||
IConfiguration[] cfgs = pt.getConfigurations();
|
||||
if (cfgs == null || cfgs.length == 0) continue;
|
||||
IToolChain tc = null;
|
||||
|
@ -85,27 +83,18 @@ public class CNewWizard extends AbstractCWizard {
|
|||
if (tc == null) continue;
|
||||
h.addTc(tc);
|
||||
|
||||
WizardItemData wd = new WizardItemData();
|
||||
String pId = null;
|
||||
if (CDTPrefUtil.getBool(CDTPrefUtil.KEY_OTHERS)) {
|
||||
if (oldsRoot == null) {
|
||||
oldsRoot = new WizardItemData();
|
||||
oldsRoot.name = Messages.getString("CNewWizard.0"); //$NON-NLS-1$
|
||||
oldsRoot.handler = null;
|
||||
oldsRoot.image =IMG0;
|
||||
oldsRoot.id = oldsRoot.name;
|
||||
oldsRoot.parentId = null;
|
||||
oldsRoot = new EntryDescriptor(OTHERS_LABEL, null, OTHERS_LABEL, true, null, null);
|
||||
items.add(oldsRoot);
|
||||
}
|
||||
wd.parentId = oldsRoot.id;
|
||||
pId = oldsRoot.getId();
|
||||
} else { // do not group to <Others>
|
||||
wd.parentId = null;
|
||||
pId = null;
|
||||
}
|
||||
wd.name = h.getName();
|
||||
wd.handler = h;
|
||||
wd.image = h.getIcon();
|
||||
wd.id = h.getName();
|
||||
items.add(wd);
|
||||
items.add(new EntryDescriptor(pt.getId(), pId, pt.getName(), true, h, IMG));
|
||||
}
|
||||
return (WizardItemData[])items.toArray(new WizardItemData[items.size()]);
|
||||
return (EntryDescriptor[])items.toArray(new EntryDescriptor[items.size()]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,9 @@ package org.eclipse.cdt.managedbuilder.ui.wizards;
|
|||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
@ -34,6 +36,7 @@ import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin;
|
|||
import org.eclipse.cdt.managedbuilder.ui.properties.Messages;
|
||||
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
|
||||
import org.eclipse.cdt.ui.wizards.CWizardHandler;
|
||||
import org.eclipse.cdt.ui.wizards.EntryDescriptor;
|
||||
import org.eclipse.cdt.ui.wizards.IWizardItemsListListener;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -45,7 +48,6 @@ import org.eclipse.jface.wizard.IWizardPage;
|
|||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
|
@ -68,25 +70,32 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
|
|||
Messages.getString("CWizardHandler.4") + //$NON-NLS-1$
|
||||
Messages.getString("CWizardHandler.5"); //$NON-NLS-1$
|
||||
|
||||
protected SortedMap tcs = new TreeMap();
|
||||
protected SortedMap full_tcs = new TreeMap();
|
||||
private String propertyId = null;
|
||||
private IProjectType pt = null;
|
||||
protected IWizardItemsListListener listener;
|
||||
protected CDTConfigWizardPage fConfigPage;
|
||||
private IToolChain[] savedToolChains = null;
|
||||
private IWizard wizard;
|
||||
private EntryDescriptor entryDescriptor = null;
|
||||
|
||||
public MBSWizardHandler(String _name, IProjectType _pt, Image _image, Composite p, IWizard w) {
|
||||
super(p, Messages.getString("CWizardHandler.0"), _name, _image); //$NON-NLS-1$
|
||||
public MBSWizardHandler(IProjectType _pt, Composite p, IWizard w) {
|
||||
super(p, Messages.getString("CWizardHandler.0"), _pt.getName()); //$NON-NLS-1$
|
||||
pt = _pt;
|
||||
if (w.getStartingPage() instanceof IWizardItemsListListener)
|
||||
listener = (IWizardItemsListListener)w.getStartingPage();
|
||||
wizard = w;
|
||||
setWizard(w);
|
||||
}
|
||||
|
||||
public MBSWizardHandler(IBuildPropertyValue val, Image _image, Composite p, IWizard w) {
|
||||
super(p, Messages.getString("CWizardHandler.0"), val.getName(), _image); //$NON-NLS-1$
|
||||
public MBSWizardHandler(String name, Composite p, IWizard w) {
|
||||
super(p, Messages.getString("CWizardHandler.0"), name); //$NON-NLS-1$
|
||||
setWizard(w);
|
||||
}
|
||||
|
||||
public MBSWizardHandler(IBuildPropertyValue val, Composite p, IWizard w) {
|
||||
super(p, Messages.getString("CWizardHandler.0"), val.getName()); //$NON-NLS-1$
|
||||
propertyId = val.getId();
|
||||
setWizard(w);
|
||||
}
|
||||
private void setWizard(IWizard w) {
|
||||
if (w.getStartingPage() instanceof IWizardItemsListListener)
|
||||
listener = (IWizardItemsListListener)w.getStartingPage();
|
||||
wizard = w;
|
||||
|
@ -98,13 +107,13 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
|
|||
if (table == null) {
|
||||
table = new Table(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
|
||||
table.setToolTipText(tooltip);
|
||||
Iterator it = tcs.keySet().iterator();
|
||||
Iterator it = tc_filter(full_tcs.keySet()).iterator();
|
||||
int counter = 0;
|
||||
int position = 0;
|
||||
while (it.hasNext()) {
|
||||
TableItem ti = new TableItem(table, SWT.NONE);
|
||||
String s = (String)it.next();
|
||||
Object obj = tcs.get(s);
|
||||
Object obj = full_tcs.get(s);
|
||||
String id = CDTPrefUtil.NULL;
|
||||
if (obj instanceof IToolChain) {
|
||||
IToolChain tc = (IToolChain)obj;
|
||||
|
@ -119,7 +128,7 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
|
|||
if (position == 0 && preferred.contains(id)) position = counter;
|
||||
counter++;
|
||||
}
|
||||
if (tcs.size() > 0) table.select(position);
|
||||
if (counter > 0) table.select(position);
|
||||
|
||||
table.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
|
@ -151,7 +160,7 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
|
|||
cfgs = ManagedBuildManager.getExtensionConfigurations(tc, pt);
|
||||
}
|
||||
if (cfgs == null || cfgs.length == 0) return;
|
||||
tcs.put(tc.getUniqueRealName(), tc);
|
||||
full_tcs.put(tc.getUniqueRealName(), tc);
|
||||
}
|
||||
|
||||
public void createProject(IProject project, boolean defaults) throws CoreException {
|
||||
|
@ -226,8 +235,8 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
|
|||
}
|
||||
}
|
||||
public String getHeader() { return head; }
|
||||
public String getName() { return name; }
|
||||
public Image getIcon() { return image; }
|
||||
// public String getName() { return name; }
|
||||
// public Image getIcon() { return null; /*image;*/ }
|
||||
public boolean isDummy() { return false; }
|
||||
public boolean supportsPreferred() { return true; }
|
||||
|
||||
|
@ -266,7 +275,7 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
|
|||
return ts;
|
||||
}
|
||||
public int getToolChainsCount() {
|
||||
return tcs.size();
|
||||
return tc_filter(full_tcs.keySet()).size();
|
||||
}
|
||||
public String getPropertyId() {
|
||||
return propertyId;
|
||||
|
@ -333,5 +342,50 @@ public class MBSWizardHandler extends CWizardHandler implements ICBuildWizardHan
|
|||
CoreModel.getDefault().setProjectDescription(newProject, prjd);
|
||||
} catch (CoreException e) {}
|
||||
}
|
||||
|
||||
public boolean isApplicable(EntryDescriptor data) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void initialize(EntryDescriptor data) throws CoreException {
|
||||
entryDescriptor = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (entryDescriptor == null)
|
||||
return full;
|
||||
Set out = new LinkedHashSet(full.size());
|
||||
Iterator it = full.iterator();
|
||||
while (it.hasNext()) {
|
||||
String s = (String)it.next();
|
||||
// checks for TC compatibility are to be here
|
||||
out.add(s);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones itself.
|
||||
*/
|
||||
public Object clone() {
|
||||
MBSWizardHandler clone = (MBSWizardHandler)super.clone();
|
||||
if (clone != null) {
|
||||
clone.propertyId = propertyId;
|
||||
clone.pt = pt;
|
||||
clone.listener = listener;
|
||||
clone.wizard = wizard;
|
||||
clone.entryDescriptor = entryDescriptor; // the same !
|
||||
clone.fConfigPage = fConfigPage; // the same !
|
||||
clone.full_tcs = full_tcs; // the same !
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,26 +21,26 @@ import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
|
|||
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
|
||||
import org.eclipse.cdt.managedbuilder.internal.core.ToolChain;
|
||||
import org.eclipse.cdt.managedbuilder.ui.properties.Messages;
|
||||
import org.eclipse.cdt.ui.newui.UIMessages;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.wizard.IWizard;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
public class STDWizardHandler extends MBSWizardHandler {
|
||||
|
||||
public STDWizardHandler(String _name, Image _image, Composite p, IWizard w) {
|
||||
super(_name, null, _image, p, w);
|
||||
public STDWizardHandler(Composite p, IWizard w) {
|
||||
super(Messages.getString("StdBuildWizard.0"), p, w); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void addTc(IToolChain tc) {
|
||||
if (tc == null) {
|
||||
tcs.put(UIMessages.getString("StdProjectTypeHandler.0"), null); //$NON-NLS-1$
|
||||
full_tcs.put(UIMessages.getString("StdProjectTypeHandler.0"), null); //$NON-NLS-1$
|
||||
} else {
|
||||
if (tc.isAbstract() || tc.isSystemObject()) return;
|
||||
// unlike CWizardHandler, we don't check for configs
|
||||
tcs.put(tc.getUniqueRealName(), tc);
|
||||
full_tcs.put(tc.getUniqueRealName(), tc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class STDWizardHandler extends MBSWizardHandler {
|
|||
* If no toolchains selected by user, use default toolchain
|
||||
*/
|
||||
public IToolChain[] getSelectedToolChains() {
|
||||
if (tcs.size() == 0 || table.getSelection().length == 0)
|
||||
if (full_tcs.size() == 0 || table.getSelection().length == 0)
|
||||
return new IToolChain[] { null };
|
||||
else
|
||||
return super.getSelectedToolChains();
|
||||
|
|
|
@ -13,23 +13,31 @@ package org.eclipse.cdt.managedbuilder.ui.wizards;
|
|||
import org.eclipse.cdt.managedbuilder.core.IToolChain;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
import org.eclipse.cdt.managedbuilder.ui.properties.Messages;
|
||||
import org.eclipse.cdt.ui.wizards.WizardItemData;
|
||||
import org.eclipse.cdt.ui.wizards.EntryDescriptor;
|
||||
import org.eclipse.jface.wizard.IWizard;
|
||||
|
||||
public class StdBuildWizard extends AbstractCWizard {
|
||||
private static final String NAME = Messages.getString("StdBuildWizard.0"); //$NON-NLS-1$
|
||||
|
||||
public WizardItemData[] createItems(boolean supportedOnly, IWizard wizard) {
|
||||
STDWizardHandler h = new STDWizardHandler(Messages.getString("StdBuildWizard.0"), IMG0, parent, wizard); //$NON-NLS-1$
|
||||
public EntryDescriptor[] createItems(boolean supportedOnly, IWizard wizard) {
|
||||
STDWizardHandler h = new STDWizardHandler(parent, wizard);
|
||||
h.addTc(null); // add default toolchain
|
||||
IToolChain[] tcs = ManagedBuildManager.getRealToolChains();
|
||||
for (int i=0; i<tcs.length; i++)
|
||||
if (!supportedOnly || isValid(tcs[i])) h.addTc(tcs[i]);
|
||||
WizardItemData wd = new WizardItemData();
|
||||
wd.name = h.getName();
|
||||
wd.handler = h;
|
||||
wd.image = h.getIcon();
|
||||
wd.id = h.getName();
|
||||
wd.parentId = null;
|
||||
return new WizardItemData[] {wd};
|
||||
EntryDescriptor wd = new EntryDescriptor(NAME, null, NAME, false, h, null);
|
||||
return new EntryDescriptor[] {wd};
|
||||
|
||||
// test only: creating items like of Templates
|
||||
/*
|
||||
EntryDescriptor[] out = new EntryDescriptor[6];
|
||||
out[5] = wd;
|
||||
for (int i=0; i<5; i++) {
|
||||
out[i] = new EntryDescriptor("Template #" + i,
|
||||
"org.eclipse.cdt.build.core.buildArtefactType.exe",
|
||||
"Template" + i, false, null, null);
|
||||
}
|
||||
return out;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
|||
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.ui.newui.AbstractExportTab.ExtData;
|
||||
import org.eclipse.cdt.ui.wizards.EntryDescriptor;
|
||||
|
||||
public class CDTListComparator implements Comparator {
|
||||
private static CDTListComparator comparator = null;
|
||||
|
@ -51,7 +52,11 @@ public class CDTListComparator implements Comparator {
|
|||
IConfigurationElement e2 = (IConfigurationElement)b;
|
||||
return AbstractPage.getWeight(e1).compareTo(AbstractPage.getWeight(e2));
|
||||
}
|
||||
|
||||
if (a instanceof EntryDescriptor) {
|
||||
EntryDescriptor c1 = (EntryDescriptor) a;
|
||||
EntryDescriptor c2 = (EntryDescriptor) b;
|
||||
return c1.getName().compareToIgnoreCase(c2.getName());
|
||||
}
|
||||
return a.toString().compareTo(b.toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.eclipse.jface.wizard.WizardPage;
|
|||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
|
@ -49,7 +50,11 @@ import org.eclipse.cdt.ui.newui.ProjectContentsArea;
|
|||
import org.eclipse.cdt.ui.newui.UIMessages;
|
||||
import org.eclipse.cdt.ui.newui.ProjectContentsArea.IErrorMessageReporter;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
|
||||
public class CDTMainWizardPage extends WizardPage implements IWizardItemsListListener {
|
||||
private static final Image IMG_CATEGORY = CPluginImages.get(CPluginImages.IMG_OBJS_SEARCHFOLDER);
|
||||
private static final Image IMG_ITEM = CPluginImages.get(CPluginImages.IMG_OBJS_VARIABLE);
|
||||
|
||||
public static final String PAGE_ID = "org.eclipse.cdt.managedbuilder.ui.wizard.NewModelProjectWizardPage"; //$NON-NLS-1$
|
||||
|
||||
|
@ -57,6 +62,7 @@ import org.eclipse.cdt.ui.newui.ProjectContentsArea.IErrorMessageReporter;
|
|||
private static final String ELEMENT_NAME = "wizard"; //$NON-NLS-1$
|
||||
private static final String CLASS_NAME = "class"; //$NON-NLS-1$
|
||||
private static final String HELP_CTX = "org.eclipse.ui.ide.new_project_wizard_page_context"; //$NON-NLS-1$
|
||||
private static final String DESC = "EntryDescriptor"; //$NON-NLS-1$
|
||||
// constants
|
||||
private static final int SIZING_TEXT_FIELD_WIDTH = 250;
|
||||
|
||||
|
@ -136,7 +142,7 @@ import org.eclipse.cdt.ui.newui.ProjectContentsArea.IErrorMessageReporter;
|
|||
public void widgetSelected(SelectionEvent e) {
|
||||
TreeItem[] tis = tree.getSelection();
|
||||
if (tis == null || tis.length == 0) return;
|
||||
switchTo((ICWizardHandler)tis[0].getData());
|
||||
switchTo((ICWizardHandler)tis[0].getData(), (EntryDescriptor)tis[0].getData(DESC));
|
||||
setPageComplete(validatePage());
|
||||
}});
|
||||
|
||||
|
@ -416,7 +422,7 @@ import org.eclipse.cdt.ui.newui.ProjectContentsArea.IErrorMessageReporter;
|
|||
if (w == null) return null;
|
||||
|
||||
w.setDependentControl(right, ls);
|
||||
WizardItemData[] wd = w.createItems(show_sup.getSelection(), wizard);
|
||||
EntryDescriptor[] wd = w.createItems(show_sup.getSelection(), wizard);
|
||||
for (int x=0; x<wd.length; x++) items.add(wd[x]);
|
||||
}
|
||||
}
|
||||
|
@ -443,38 +449,55 @@ import org.eclipse.cdt.ui.newui.ProjectContentsArea.IErrorMessageReporter;
|
|||
}
|
||||
|
||||
private static void addItemsToTree(Tree tree, ArrayList items) {
|
||||
ArrayList tis = new ArrayList(items.size());
|
||||
ArrayList its = new ArrayList(items.size());
|
||||
// Sorting is disabled because of users requests
|
||||
// Collections.sort(items, CDTListComparator.getInstance());
|
||||
|
||||
ArrayList placedTreeItemsList = new ArrayList(items.size());
|
||||
ArrayList placedEntryDescriptorsList = new ArrayList(items.size());
|
||||
Iterator it = items.iterator();
|
||||
while (it.hasNext()) {
|
||||
WizardItemData wd = (WizardItemData)it.next();
|
||||
if (wd.parentId == null) {
|
||||
EntryDescriptor wd = (EntryDescriptor)it.next();
|
||||
if (wd.getParentId() == null) {
|
||||
wd.setPath(wd.getId());
|
||||
TreeItem ti = new TreeItem(tree, SWT.NONE);
|
||||
ti.setText(wd.name);
|
||||
ti.setData(wd.handler);
|
||||
if (wd.image != null)ti.setImage(wd.image);
|
||||
tis.add(ti);
|
||||
its.add(wd);
|
||||
ti.setText(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 it2 = items.iterator();
|
||||
while (it2.hasNext()) {
|
||||
WizardItemData wd1 = (WizardItemData)it2.next();
|
||||
if (wd1.parentId == null) continue;
|
||||
for (int i=0; i<its.size(); i++) {
|
||||
WizardItemData wd2 = (WizardItemData)its.get(i);
|
||||
if (wd2.id.equals(wd1.parentId)) {
|
||||
EntryDescriptor wd1 = (EntryDescriptor)it2.next();
|
||||
if (wd1.getParentId() == null) continue;
|
||||
for (int i=0; i<placedEntryDescriptorsList.size(); i++) {
|
||||
EntryDescriptor wd2 = (EntryDescriptor)placedEntryDescriptorsList.get(i);
|
||||
if (wd2.getId().equals(wd1.getParentId())) {
|
||||
found = true;
|
||||
TreeItem p = (TreeItem)tis.get(i);
|
||||
wd1.setParentId(null);
|
||||
ICWizardHandler h = wd2.getHandler();
|
||||
if (h == null && !wd1.isCategory())
|
||||
break;
|
||||
|
||||
wd1.setPath(wd2.getPath() + "/" + wd1.getId()); //$NON-NLS-1$
|
||||
wd1.setParent(wd2);
|
||||
if (wd1.getHandler() == null && !wd1.isCategory())
|
||||
wd1.setHandler((ICWizardHandler)h.clone());
|
||||
if (h != null && !h.isApplicable(wd1))
|
||||
break;
|
||||
|
||||
TreeItem p = (TreeItem)placedTreeItemsList.get(i);
|
||||
TreeItem ti = new TreeItem(p, SWT.NONE);
|
||||
ti.setText(wd1.name);
|
||||
ti.setData(wd1.handler);
|
||||
if (wd1.image != null)ti.setImage(wd1.image);
|
||||
tis.add(ti);
|
||||
its.add(wd1);
|
||||
wd1.parentId = null;
|
||||
ti.setText(wd1.getName());
|
||||
ti.setData(wd1.getHandler());
|
||||
ti.setData(DESC, wd1);
|
||||
ti.setImage(calcImage(wd1));
|
||||
placedTreeItemsList.add(ti);
|
||||
placedEntryDescriptorsList.add(wd1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -482,18 +505,17 @@ import org.eclipse.cdt.ui.newui.ProjectContentsArea.IErrorMessageReporter;
|
|||
// repeat iterations until all items are placed.
|
||||
if (!found) break;
|
||||
}
|
||||
// show orphan elements, if any
|
||||
Iterator it3 = items.iterator();
|
||||
while (it3.hasNext()) {
|
||||
WizardItemData wd = (WizardItemData)it3.next();
|
||||
if (wd.parentId == null) continue;
|
||||
TreeItem ti = new TreeItem(tree, SWT.NONE);
|
||||
ti.setText(wd.name + " @ " + wd.parentId); //$NON-NLS-1$
|
||||
ti.setData(wd.handler);
|
||||
if (wd.image != null)ti.setImage(wd.image);
|
||||
}
|
||||
// orphan elements (with not-existing parentId) are ignored
|
||||
}
|
||||
|
||||
|
||||
private void switchTo(ICWizardHandler h, EntryDescriptor ed) {
|
||||
if (h == null) h = ed.getHandler();
|
||||
try {
|
||||
if (h != null) h.initialize(ed);
|
||||
} catch (CoreException e) { h = null; }
|
||||
switchTo(h);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param h - new handler
|
||||
*/
|
||||
|
@ -511,5 +533,11 @@ import org.eclipse.cdt.ui.newui.ProjectContentsArea.IErrorMessageReporter;
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,16 +50,14 @@ public class CWizardHandler implements ICWizardHandler {
|
|||
|
||||
protected String head;
|
||||
protected String name;
|
||||
protected Image image;
|
||||
protected Composite parent;
|
||||
protected Table table;
|
||||
protected boolean supportedOnly = true;
|
||||
|
||||
public CWizardHandler(Composite _parent, String _head, String _name, Image _image) {
|
||||
public CWizardHandler(Composite _parent, String _head, String _name) {
|
||||
parent = _parent;
|
||||
name = _name;
|
||||
image = _image;
|
||||
head = _head;
|
||||
name = _name;
|
||||
}
|
||||
|
||||
public void handleSelection() {
|
||||
|
@ -84,7 +82,6 @@ public class CWizardHandler implements ICWizardHandler {
|
|||
|
||||
public String getHeader() { return head; }
|
||||
public String getName() { return name; }
|
||||
public Image getIcon() { return image; }
|
||||
public String getErrorMessage() { return null; }
|
||||
|
||||
public void setSupportedOnly(boolean supp) { supportedOnly = supp;}
|
||||
|
@ -98,5 +95,16 @@ public class CWizardHandler implements ICWizardHandler {
|
|||
public boolean isChanged() { return true; }
|
||||
public void saveState() {}
|
||||
public void postProcess(IProject proj) {}
|
||||
|
||||
public boolean isApplicable(EntryDescriptor data) { return true; }
|
||||
public void initialize(EntryDescriptor data) throws CoreException {}
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
CWizardHandler clone = (CWizardHandler)super.clone();
|
||||
clone.parent = parent;
|
||||
clone.head = head;
|
||||
clone.name = name;
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) { return null; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Intel Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Intel Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.wizards;
|
||||
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
/**
|
||||
* This class stores data for each tree item
|
||||
* in "Project types" tree of New Project Wizard.
|
||||
*/
|
||||
public class EntryDescriptor {
|
||||
private String id = null;
|
||||
private String name = null;
|
||||
private boolean isCategory = false;
|
||||
private String parentId = null;
|
||||
private Image image = null;
|
||||
private ICWizardHandler handler = null;
|
||||
private String path = null;
|
||||
private EntryDescriptor parent = null;
|
||||
|
||||
public EntryDescriptor (String _id, String _par, String _name, boolean _cat, ICWizardHandler _h, Image _image) {
|
||||
id = _id;
|
||||
parentId = _par;
|
||||
name = _name;
|
||||
isCategory = _cat;
|
||||
handler = _h;
|
||||
image = _image;
|
||||
}
|
||||
// these parameters are set in constructor only
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public boolean isCategory() {
|
||||
return isCategory;
|
||||
}
|
||||
public Image getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
// these parameters can be set anywhere
|
||||
public void setParentId(String pId) {
|
||||
parentId = pId;
|
||||
}
|
||||
public String getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setPath(String p) {
|
||||
path = p;
|
||||
}
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setParent(EntryDescriptor p) {
|
||||
parent = p;
|
||||
}
|
||||
public EntryDescriptor getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setHandler(ICWizardHandler h) {
|
||||
handler = h;
|
||||
}
|
||||
public ICWizardHandler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ public interface ICNewWizard {
|
|||
* @param supportedOnly - whether display supported types only
|
||||
* @param wizard - New Project wizard to be passed to ICWizardHandler
|
||||
*/
|
||||
public WizardItemData[] createItems(boolean supportedOnly, IWizard wizard);
|
||||
public EntryDescriptor[] createItems(boolean supportedOnly, IWizard wizard);
|
||||
|
||||
/**
|
||||
* Implementor will be informed about widget where additional
|
||||
|
|
|
@ -15,9 +15,8 @@ import java.util.List;
|
|||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.wizard.IWizardPage;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
public interface ICWizardHandler {
|
||||
public interface ICWizardHandler extends Cloneable {
|
||||
static final String ARTIFACT = "org.eclipse.cdt.build.core.buildArtefactType"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
|
@ -30,18 +29,14 @@ public interface ICWizardHandler {
|
|||
* Called when user leaves corresponding item in wizard tree
|
||||
*/
|
||||
public void handleUnSelection();
|
||||
/**
|
||||
* @return label of tree item
|
||||
*/
|
||||
public String getName();
|
||||
/**
|
||||
* @return icon for tree item
|
||||
*/
|
||||
public Image getIcon();
|
||||
/**
|
||||
* @return text for label above handler-specific pane
|
||||
*/
|
||||
public String getHeader();
|
||||
/**
|
||||
* @return text for label in left tree
|
||||
*/
|
||||
public String getName();
|
||||
/**
|
||||
* @return 1st handler-specific page
|
||||
*/
|
||||
|
@ -94,4 +89,21 @@ public interface ICWizardHandler {
|
|||
* since last call to saveState()
|
||||
*/
|
||||
public boolean isChanged();
|
||||
/**
|
||||
* Checks whether this item can be added to Wizard tree
|
||||
*
|
||||
* @param data - Wizard Item data to be added
|
||||
* as child to current Wizard item
|
||||
* @return - true if item can be added.
|
||||
*/
|
||||
public boolean isApplicable(EntryDescriptor data);
|
||||
/**
|
||||
* Initializes the handler to be used for the specified entry
|
||||
*
|
||||
* @param data - Wizard Item data to be handled
|
||||
* @throws CoreException
|
||||
*/
|
||||
public void initialize(EntryDescriptor data) throws CoreException;
|
||||
|
||||
public Object clone();
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Intel Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Intel Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.wizards;
|
||||
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
/**
|
||||
* This class stores data for each tree item
|
||||
* in "Project types" tree of New Project Wizard.
|
||||
*/
|
||||
public class WizardItemData {
|
||||
public String id = null;
|
||||
public String parentId = null;
|
||||
public String name = null;
|
||||
public Image image = null;
|
||||
public ICWizardHandler handler = null;
|
||||
}
|
Loading…
Add table
Reference in a new issue