1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug #190155 : The MBS new project wizard allows finishing without asking custom pages first

This commit is contained in:
Oleg Krasilnikov 2007-09-26 14:17:16 +00:00
parent 8c4edac2ff
commit 4e30fbe8a0
4 changed files with 118 additions and 151 deletions

View file

@ -12,11 +12,7 @@ package org.eclipse.cdt.managedbuilder.ui.wizards;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IProjectType; import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
@ -24,7 +20,6 @@ import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIImages;
import org.eclipse.cdt.ui.newui.CDTPrefUtil; import org.eclipse.cdt.ui.newui.CDTPrefUtil;
import org.eclipse.cdt.ui.newui.UIMessages; import org.eclipse.cdt.ui.newui.UIMessages;
import org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard; import org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard;
import org.eclipse.cdt.ui.wizards.CDTMainWizardPage;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.CheckboxTableViewer;
@ -73,6 +68,7 @@ public class CDTConfigWizardPage extends WizardPage {
private MBSWizardHandler handler; private MBSWizardHandler handler;
public boolean pagesLoaded = false; public boolean pagesLoaded = false;
private IToolChain[] visitedTCs = null; private IToolChain[] visitedTCs = null;
IWizardPage[] customPages = null;
public CDTConfigWizardPage(MBSWizardHandler h) { public CDTConfigWizardPage(MBSWizardHandler h) {
super(UIMessages.getString("CDTConfigWizardPage.0")); //$NON-NLS-1$ super(UIMessages.getString("CDTConfigWizardPage.0")); //$NON-NLS-1$
@ -81,33 +77,6 @@ public class CDTConfigWizardPage extends WizardPage {
setWizard(h.getWizard()); setWizard(h.getWizard());
} }
void addCustomPages() {
if (pagesLoaded) return;
pagesLoaded = true;
if (! (getWizard() instanceof CDTCommonProjectWizard)) return;
CDTCommonProjectWizard wz = (CDTCommonProjectWizard)getWizard();
IWizardPage p = getWizard().getStartingPage();
MBSCustomPageManager.init();
MBSCustomPageManager.addStockPage(p, CDTMainWizardPage.PAGE_ID);
MBSCustomPageManager.addStockPage(this, CDTConfigWizardPage.PAGE_ID);
setCustomPagesFilter(wz);
// load all custom pages specified via extensions
try {
MBSCustomPageManager.loadExtensions();
} catch (BuildException e) { e.printStackTrace(); }
IWizardPage[] customPages = MBSCustomPageManager.getCustomPages();
if (customPages != null) {
for (int k = 0; k < customPages.length; k++) {
wz.addPage(customPages[k]);
}
}
}
public CfgHolder[] getCfgItems(boolean getDefault) { public CfgHolder[] getCfgItems(boolean getDefault) {
CfgHolder[] its; CfgHolder[] its;
if (getDefault || table == null || !isVisited()) if (getDefault || table == null || !isVisited())
@ -358,50 +327,7 @@ public class CDTConfigWizardPage extends WizardPage {
} }
public IWizardPage getNextPage() { public IWizardPage getNextPage() {
addCustomPages(); pagesLoaded = true;
return MBSCustomPageManager.getNextPage(PAGE_ID); return MBSCustomPageManager.getNextPage(PAGE_ID);
} }
private void setCustomPagesFilter(CDTCommonProjectWizard wz) {
String[] natures = wz.getNatures();
if (natures == null || natures.length == 0)
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.NATURE, null);
else if (natures.length == 1)
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.NATURE, natures[0]);
else {
Set x = new TreeSet();
for (int i=0; i<natures.length; i++) x.add(natures[i]);
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.NATURE, x);
}
// Project type can be obtained either from Handler (for old-style projects),
// or multiple values will be got from separate ToolChains (for new-style).
boolean ptIsNull = (handler.getProjectType() == null);
if (!ptIsNull)
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, handler.getProjectType().getId());
IToolChain[] tcs = handler.getSelectedToolChains();
int n = (tcs == null) ? 0 : tcs.length;
Set x = new TreeSet();
Set y = new TreeSet();
for (int i=0; i<n; i++) {
if (tcs[i] == null) // --- NO TOOLCHAIN ---
continue; // has no custom pages.
x.add(tcs[i]);
IConfiguration cfg = tcs[i].getParent();
if (cfg == null)
continue;
IProjectType pt = cfg.getProjectType();
if (pt != null)
y.add(pt.getId());
}
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.TOOLCHAIN, x);
if (ptIsNull) {
if (y.size() > 0)
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, y);
else
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, null);
}
}
} }

View file

@ -238,13 +238,11 @@ public final class MBSCustomPageData
// if no toolchains specified then always return true // if no toolchains specified then always return true
if (toolchainSet.size() == 0) if (toolchainSet.size() == 0)
return true; return true;
Iterator iterator = toolchainSet.iterator(); Iterator iterator = toolchainSet.iterator();
while (iterator.hasNext()) while (iterator.hasNext())
{ {
ToolchainData tcd = (ToolchainData) iterator.next(); ToolchainData tcd = (ToolchainData) iterator.next();
// look for toolchain with same id. The id in the tool-chain data should never // look for toolchain with same id. The id in the tool-chain data should never
// contain a version suffix. // contain a version suffix.
if (tcd.getId().equals(id)) if (tcd.getId().equals(id))
@ -252,22 +250,13 @@ public final class MBSCustomPageData
// if we don't check versions then we're done // if we don't check versions then we're done
if (tcd.getVersionsSupported() == null) if (tcd.getVersionsSupported() == null)
return true; return true;
// is the toolchain of one of the specified versions? // is the toolchain of one of the specified versions?
for (int k = 0; k < tcd.getVersionsSupported().length; k++) for (int k = 0; k < tcd.getVersionsSupported().length; k++) {
{
// check for an exact version match
if (tcd.getVersionsSupported()[k].equals(version)) if (tcd.getVersionsSupported()[k].equals(version))
{
return true; return true;
}
} }
} }
} }
return false; return false;
} }

View file

@ -338,46 +338,39 @@ public final class MBSCustomPageManager
if(page == null) if(page == null)
return false; return false;
if (getPageHideStatus(pageID)) return false; if (getPageHideStatus(pageID))
return false;
// first, find out what project type, toolchain, and nature have been set // first, find out what project type, toolchain, and nature have been set
Map pagePropertiesMap = (Map) pageIDtoPagePropertiesMap.get(PAGE_ID); Map pagePropertiesMap = (Map) pageIDtoPagePropertiesMap.get(PAGE_ID);
Object projectType = pagePropertiesMap.get(PROJECT_TYPE); Object projectType = pagePropertiesMap.get(PROJECT_TYPE);
Set toolchainSet = (Set) pagePropertiesMap.get(TOOLCHAIN); List toolchainList = (List) pagePropertiesMap.get(TOOLCHAIN);
Object nature = pagePropertiesMap.get(NATURE); Object nature = pagePropertiesMap.get(NATURE);
// does the page follow nature and project type constraints? // does the page follow nature and project type constraints?
if (page.shouldBeVisibleForNature(nature) if (page.shouldBeVisibleForNature(nature)
&& page.shouldBeVisibleForProjectType(projectType)) && page.shouldBeVisibleForProjectType(projectType))
{ {
MBSCustomPageData.ToolchainData[] toolchainData = page.getToolchains(); MBSCustomPageData.ToolchainData[] toolchainData = page.getToolchains();
// if no toolchains are specified then we're done // if no toolchains are specified then we're done
if (toolchainData == null || toolchainSet == null) if (toolchainData == null || toolchainList == null)
{
return true; return true;
}
// otherwise, iterate through the toolchains to see if one matches // otherwise, iterate through the toolchains to see if one matches
for (int k = 0; k < toolchainData.length; k++) for (int k = 0; k < toolchainData.length; k++)
{ {
// check all toolchains, see if there is one for which we should be present // check all toolchains, see if there is one for which we should be present
Iterator toolchainIterator = toolchainSet.iterator(); Iterator toolchainIterator = toolchainList.iterator();
while (toolchainIterator.hasNext()) while (toolchainIterator.hasNext())
{ {
IToolChain toolchain = (IToolChain) toolchainIterator.next(); IToolChain toolchain = (IToolChain) toolchainIterator.next();
if(toolchain != null){ if(toolchain != null){
String id = ManagedBuildManager.getIdFromIdAndVersion(toolchain.getId()); String id = ManagedBuildManager.getIdFromIdAndVersion(toolchain.getId());
String version = ManagedBuildManager.getVersionFromIdAndVersion(toolchain.getId()); String version = ManagedBuildManager.getVersionFromIdAndVersion(toolchain.getId());
// check the ID and version // check the ID and version
if (page.shouldBeVisibleForToolchain(id, version)) if (page.shouldBeVisibleForToolchain(id, version))
{
return true; return true;
}
} }
} }
} }
@ -459,56 +452,20 @@ public final class MBSCustomPageManager
{ {
// find the current page in the set of pages // find the current page in the set of pages
MBSCustomPageData pageData = getPageData(currentPageID); MBSCustomPageData pageData = getPageData(currentPageID);
MBSCustomPageData currentData = null;
Iterator iterator = pageSet.iterator(); Iterator iterator = pageSet.iterator();
while (iterator.hasNext()) while (iterator.hasNext())
{ {
currentData = (MBSCustomPageData) iterator.next(); if (pageData.equals((MBSCustomPageData)iterator.next())) {
IWizardPage nextPage = null;
if (currentData == pageData) while (iterator.hasNext() && nextPage == null)
{
// we found the page we're looking for so stop looking
break;
}
}
if (currentData == pageData)
{
// we found our page
// look for the next page that satisfies all project type, toolchain, and nature criteria
// first, find out what project type, toolchain, and nature have been set
// Map pagePropertiesMap = (Map) pageIDtoPagePropertiesMap.get(PAGE_ID);
// String projectType = pagePropertiesMap.get(PROJECT_TYPE).toString();
// Set toolchainSet = (Set) pagePropertiesMap.get(TOOLCHAIN);
// String nature = pagePropertiesMap.get(NATURE).toString();
IWizardPage nextPage = null;
boolean pageFound = false;
while (iterator.hasNext() && !pageFound)
{
MBSCustomPageData potentialPage = (MBSCustomPageData) iterator.next();
if (isPageVisible(potentialPage.getID()))
{ {
pageFound = true; MBSCustomPageData potentialPage = (MBSCustomPageData) iterator.next();
nextPage = potentialPage.getWizardPage(); if (isPageVisible(potentialPage.getID()))
nextPage = potentialPage.getWizardPage();
} }
}
if (pageFound)
return nextPage; return nextPage;
}
} }
return null; return null;
} }

View file

@ -21,6 +21,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.TreeSet;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
@ -30,6 +31,7 @@ import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.core.templateengine.process.ProcessFailureException; import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyValue; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyValue;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuilder; import org.eclipse.cdt.managedbuilder.core.IBuilder;
import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IProjectType; import org.eclipse.cdt.managedbuilder.core.IProjectType;
@ -45,6 +47,7 @@ import org.eclipse.cdt.ui.templateengine.Template;
import org.eclipse.cdt.ui.templateengine.TemplateEngineUI; import org.eclipse.cdt.ui.templateengine.TemplateEngineUI;
import org.eclipse.cdt.ui.templateengine.TemplateEngineUIUtil; import org.eclipse.cdt.ui.templateengine.TemplateEngineUIUtil;
import org.eclipse.cdt.ui.templateengine.pages.UIWizardPage; import org.eclipse.cdt.ui.templateengine.pages.UIWizardPage;
import org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard;
import org.eclipse.cdt.ui.wizards.CDTMainWizardPage; import org.eclipse.cdt.ui.wizards.CDTMainWizardPage;
import org.eclipse.cdt.ui.wizards.CWizardHandler; import org.eclipse.cdt.ui.wizards.CWizardHandler;
import org.eclipse.cdt.ui.wizards.EntryDescriptor; import org.eclipse.cdt.ui.wizards.EntryDescriptor;
@ -96,6 +99,7 @@ public class MBSWizardHandler extends CWizardHandler {
// private EntryDescriptor entryDescriptor = null; // private EntryDescriptor entryDescriptor = null;
private EntryInfo entryInfo; private EntryInfo entryInfo;
protected CfgHolder[] cfgs = null; protected CfgHolder[] cfgs = null;
protected IWizardPage[] customPages;
protected static final class EntryInfo { protected static final class EntryInfo {
private SortedMap tcs; private SortedMap tcs;
@ -365,16 +369,106 @@ public class MBSWizardHandler extends CWizardHandler {
} }
table.addSelectionListener(new SelectionAdapter() { table.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
if (listener != null) handleToolChainSelection();
listener.toolChainListChanged(table.getSelectionCount());
}}); }});
} }
updatePreferred(preferred); updatePreferred(preferred);
loadCustomPages();
table.setVisible(true); table.setVisible(true);
parent.layout(); parent.layout();
if (fConfigPage != null) fConfigPage.pagesLoaded = false; if (fConfigPage != null) fConfigPage.pagesLoaded = false;
} }
private void handleToolChainSelection() {
loadCustomPages();
// Notify listener, if any.
if (listener != null)
listener.toolChainListChanged(table.getSelectionCount());
}
private void loadCustomPages() {
if (! (getWizard() instanceof CDTCommonProjectWizard))
return; // not probable
CDTCommonProjectWizard wz = (CDTCommonProjectWizard)getWizard();
if (customPages == null) {
MBSCustomPageManager.init();
MBSCustomPageManager.addStockPage(getStartingPage(), CDTMainWizardPage.PAGE_ID);
MBSCustomPageManager.addStockPage(getConfigPage(), CDTConfigWizardPage.PAGE_ID);
// load all custom pages specified via extensions
try {
MBSCustomPageManager.loadExtensions();
} catch (BuildException e) { e.printStackTrace(); }
customPages = MBSCustomPageManager.getCustomPages();
if (customPages == null)
customPages = new IWizardPage[0];
for (int k = 0; k < customPages.length; k++)
customPages[k].setWizard(wz);
}
setCustomPagesFilter(wz);
}
private void setCustomPagesFilter(CDTCommonProjectWizard wz) {
String[] natures = wz.getNatures();
if (natures == null || natures.length == 0)
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.NATURE, null);
else if (natures.length == 1)
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.NATURE, natures[0]);
else {
Set x = new TreeSet();
for (int i=0; i<natures.length; i++) x.add(natures[i]);
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.NATURE, x);
}
// Project type can be obtained either from Handler (for old-style projects),
// or multiple values will be got from separate ToolChains (for new-style).
boolean ptIsNull = (getProjectType() == null);
if (!ptIsNull)
MBSCustomPageManager.addPageProperty(
MBSCustomPageManager.PAGE_ID,
MBSCustomPageManager.PROJECT_TYPE,
getProjectType().getId()
);
IToolChain[] tcs = getSelectedToolChains();
int n = (tcs == null) ? 0 : tcs.length;
List x = new ArrayList();
Set y = new TreeSet();
for (int i=0; i<n; i++) {
if (tcs[i] == null) // --- NO TOOLCHAIN ---
continue; // has no custom pages.
x.add(tcs[i]);
IConfiguration cfg = tcs[i].getParent();
if (cfg == null)
continue;
IProjectType pt = cfg.getProjectType();
if (pt != null)
y.add(pt.getId());
}
MBSCustomPageManager.addPageProperty(
MBSCustomPageManager.PAGE_ID,
MBSCustomPageManager.TOOLCHAIN,
x);
if (ptIsNull) {
if (y.size() > 0)
MBSCustomPageManager.addPageProperty(
MBSCustomPageManager.PAGE_ID,
MBSCustomPageManager.PROJECT_TYPE,
y);
else
MBSCustomPageManager.addPageProperty(
MBSCustomPageManager.PAGE_ID,
MBSCustomPageManager.PROJECT_TYPE,
null);
}
}
public void handleUnSelection() { public void handleUnSelection() {
if (table != null) { if (table != null) {
table.setVisible(false); table.setVisible(false);
@ -450,8 +544,6 @@ public class MBSWizardHandler extends CWizardHandler {
doPostProcess(project); doPostProcess(project);
// process custom pages // process custom pages
// if (fConfigPage != null && fConfigPage.pagesLoaded)
getConfigPage().addCustomPages();
doCustom(); doCustom();
} }
@ -499,8 +591,6 @@ public class MBSWizardHandler extends CWizardHandler {
} }
} }
public String getHeader() { return head; } public String getHeader() { return head; }
// public String getName() { return name; }
// public Image getIcon() { return null; /*image;*/ }
public boolean isDummy() { return false; } public boolean isDummy() { return false; }
public boolean supportsPreferred() { return true; } public boolean supportsPreferred() { return true; }
@ -649,6 +739,11 @@ public class MBSWizardHandler extends CWizardHandler {
if(!entryInfo.canFinish(startingPage, getConfigPage())) if(!entryInfo.canFinish(startingPage, getConfigPage()))
return false; return false;
if (customPages != null)
for (int i=0; i<customPages.length; i++)
if (!customPages[i].isPageComplete())
return false;
return super.canFinich(); return super.canFinich();
} }