1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 08:55:25 +02:00

Bug #125686 and related features

This commit is contained in:
Oleg Krasilnikov 2007-03-15 17:02:55 +00:00
parent f720d9d47d
commit 65b8b57333
18 changed files with 669 additions and 365 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 835 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

View file

@ -89,10 +89,16 @@
point="org.eclipse.ui.preferencePages">
<page
name="%MakeBuildPref.name"
category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
category="org.eclipse.cdt.managedbuilder.ui.preferences.WizardPreferences"
class="org.eclipse.cdt.managedbuilder.ui.newui.PrefPage_NewCDTProject"
id="org.eclipse.cdt.managedbuilder.ui.preferences.BuildPreferences">
</page>
<page
name="%NewCDTWizardPref.name"
category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
class="org.eclipse.cdt.managedbuilder.ui.newui.PrefPage_NewCDTWizard"
id="org.eclipse.cdt.managedbuilder.ui.preferences.WizardPreferences">
</page>
</extension>
<!-- Action for Project Converter in context menu -->
@ -405,6 +411,16 @@
icon="icons/obj16/build_settings.gif"
name="%Builder.settings"
parent="org.eclipse.cdt.managedbuilder.ui.newui.PrefPage_NewCDTProject"/>
<tab
class="org.eclipse.cdt.managedbuilder.ui.newui.PreferredToolchainsTab"
name="%Preferred.toolchains"
parent="org.eclipse.cdt.managedbuilder.ui.newui.PrefPage_NewCDTWizard"/>
<tab
class="org.eclipse.cdt.managedbuilder.ui.newui.WizardDefaultsTab"
name="%Wizard.defaults"
parent="org.eclipse.cdt.managedbuilder.ui.newui.PrefPage_NewCDTWizard"/>
</extension>
<extension

View file

@ -40,6 +40,7 @@ public class ManagedBuilderUIImages {
public static final String T_BUILD= "elcl16/"; //$NON-NLS-1$
// list icons dir
public static final String T_LIST= "elcl16/"; //$NON-NLS-1$
public static final String T_OBJ= "obj16/"; //$NON-NLS-1$
// For the managed build images
@ -74,11 +75,16 @@ public class ManagedBuilderUIImages {
// new images
public static final String IMG_READ_ONLY = NAME_PREFIX + "read_only.gif"; //$NON-NLS-1$
public static final ImageDescriptor DESC_READ_ONLY = createManaged(T_LIST, IMG_READ_ONLY);
public static final ImageDescriptor DESC_READ_ONLY = createManaged(T_OBJ, IMG_READ_ONLY);
public static final String IMG_EDITABLE = NAME_PREFIX + "editable.gif"; //$NON-NLS-1$
public static final ImageDescriptor DESC_EDITABLE = createManaged(T_LIST, IMG_EDITABLE);
public static final ImageDescriptor DESC_EDITABLE = createManaged(T_OBJ, IMG_EDITABLE);
public static final String IMG_BUILT_IN = NAME_PREFIX + "built_in.gif"; //$NON-NLS-1$
public static final ImageDescriptor DESC_BUILT_IN = createManaged(T_LIST, IMG_EDITABLE);
public static final ImageDescriptor DESC_BUILT_IN = createManaged(T_OBJ, IMG_BUILT_IN);
public static final String IMG_PREFERRED = NAME_PREFIX + "preferred.gif"; //$NON-NLS-1$
public static final ImageDescriptor DESC_PREFERRED = createManaged(T_OBJ, IMG_PREFERRED);
public static final String IMG_EMPTY = NAME_PREFIX + "empty.gif"; //$NON-NLS-1$
public static final ImageDescriptor DESC_EMPTY = createManaged(T_OBJ, IMG_EMPTY);
private static ImageDescriptor createManaged(String prefix, String name) {
return createManaged(imageRegistry, prefix, name);
@ -94,10 +100,6 @@ public class ManagedBuilderUIImages {
return imageRegistry.get(key);
}
// private static ImageDescriptor create(String prefix, String name) {
// return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name));
// }
private static URL makeIconFileURL(String prefix, String name) {
StringBuffer buffer= new StringBuffer(prefix);
buffer.append(name);
@ -109,16 +111,6 @@ public class ManagedBuilderUIImages {
}
}
/**
* Sets all available image descriptors for the given action.
*/
// public static void setImageDescriptors(IAction action, String type, String relPath) {
// relPath= relPath.substring(NAME_PREFIX_LENGTH);
// action.setDisabledImageDescriptor(create(T + "d" + type, relPath)); //$NON-NLS-1$
// action.setHoverImageDescriptor(create(T + "c" + type, relPath)); //$NON-NLS-1$
// action.setImageDescriptor(create(T + "e" + type, relPath)); //$NON-NLS-1$
// }
/**
* Helper method to access the image registry from the JavaPlugin class.
*/

View file

@ -1,6 +1,8 @@
package org.eclipse.cdt.managedbuilder.ui.newui;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.ui.newui.AbstractPrefPage;
import org.eclipse.cdt.ui.newui.ICPropertyTab;
public class PrefPage_NewCDTWizard extends AbstractPrefPage {
@ -9,8 +11,16 @@ public class PrefPage_NewCDTWizard extends AbstractPrefPage {
Messages.getString("PrefPage_NewCDTWizard.1"); //$NON-NLS-1$
}
protected boolean isSingle() {
return false;
/*
* All affected settings are stored in preferences.
* Tabs are responsible for saving, after OK signal.
* No need to affect Project Description somehow.
*/
public boolean performOk() {
forEach(ICPropertyTab.OK, null);
return true;
}
public ICResourceDescription getResDesc() { return null; }
protected boolean isSingle() { return false; }
}

View file

@ -0,0 +1,140 @@
/*******************************************************************************
* 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.managedbuilder.ui.newui;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.ui.wizards.CMainWizardPage;
import org.eclipse.cdt.managedbuilder.ui.wizards.ICWizardHandler;
import org.eclipse.cdt.managedbuilder.ui.wizards.IDEWorkbenchMessages;
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
public class PreferredToolchainsTab extends AbstractCBuildPropertyTab {
protected ICWizardHandler h_selected = null;
// widgets
private Tree tree;
private Composite right;
private Button show_sup;
private Label right_label;
private Button pref1;
private Button pref0;
public void createControls(Composite parent) {
super.createControls(parent);
usercomp.setLayout(new GridLayout(1, false));
Composite c = new Composite(usercomp, SWT.NONE);
c.setLayoutData(new GridData(GridData.FILL_BOTH));
c.setLayout(new GridLayout(2, true));
Label l1 = new Label(c, SWT.NONE);
l1.setText(org.eclipse.cdt.managedbuilder.ui.wizards.IDEWorkbenchMessages.getString("CMainWizardPage.0")); //$NON-NLS-1$
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));
tree = new Tree(c, SWT.SINGLE | SWT.BORDER);
tree.setLayoutData(new GridData(GridData.FILL_BOTH));
tree.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
TreeItem[] tis = tree.getSelection();
if (tis == null || tis.length == 0) return;
switchTo((ICWizardHandler)tis[0].getData());
}});
right = new Composite(c, SWT.NONE);
right.setLayoutData(new GridData(GridData.FILL_BOTH));
right.setLayout(new PageLayout());
Label l = new Label(c,SWT.WRAP | SWT.CENTER);
l.setText(IDEWorkbenchMessages.getString("PreferredToolchainsTab.0")); //$NON-NLS-1$
GridData gd = new GridData(GridData.CENTER);
gd.horizontalSpan = 2;
l.setLayoutData(gd);
new Label(c,0).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
pref1 = new Button(c, SWT.PUSH);
pref1.setText(IDEWorkbenchMessages.getString("PreferredToolchainsTab.1")); //$NON-NLS-1$
pref1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
pref1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) { setPref(true); }} );
new Label(c,0).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
pref0 = new Button(c, SWT.PUSH);
pref0.setText(IDEWorkbenchMessages.getString("PreferredToolchainsTab.2")); //$NON-NLS-1$
pref0.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
pref0.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) { setPref(false); }} );
show_sup = new Button(c, SWT.CHECK);
show_sup.setSelection(true);
show_sup.setText(org.eclipse.cdt.managedbuilder.ui.wizards.IDEWorkbenchMessages.getString("CMainWizardPage.1")); //$NON-NLS-1$
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
show_sup.setLayoutData(gd);
show_sup.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (h_selected != null)
h_selected.setSupportedOnly(show_sup.getSelection());
switchTo(CMainWizardPage.updateData(tree, right, show_sup, null));
}} );
CDTPrefUtil.readPreferredTCs();
switchTo(CMainWizardPage.updateData(tree, right, show_sup, null));
}
private void setPref(boolean set) {
if (h_selected == null || !h_selected.supportsPreferred())
return;
IToolChain[] tcs = h_selected.getSelectedToolChains();
for (int i=0; i<tcs.length; i++) {
String id = (tcs[i] == null) ? CDTPrefUtil.NULL : tcs[i].getId();
if (set) CDTPrefUtil.addPreferredTC(id);
else CDTPrefUtil.delPreferredTC(id);
}
h_selected.updatePreferred(CDTPrefUtil.getPreferredTCs());
}
private void switchTo(ICWizardHandler h) {
if (h == null) return;
if (h_selected != null) h_selected.handleUnSelection();
h_selected = h;
right_label.setText(h_selected.getHeader());
h_selected.handleSelection();
h_selected.setSupportedOnly(show_sup.getSelection());
}
protected void performOK() {
CDTPrefUtil.savePreferredTCs();
}
protected void performApply(ICResourceDescription src, ICResourceDescription dst) { performOK();}
protected void performDefaults() {
CDTPrefUtil.cleanPreferredTCs();
h_selected.handleSelection();
}
protected void updateData(ICResourceDescription cfg) {}
}

View file

@ -0,0 +1,70 @@
/*******************************************************************************
* 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.managedbuilder.ui.newui;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.ui.newui.AbstractCPropertyTab;
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
public class WizardDefaultsTab extends AbstractCPropertyTab {
private Button show_sup;
private Button show_oth;
private Button show_mng;
public void createControls(Composite parent) {
super.createControls(parent);
usercomp.setLayout(new GridLayout(1, false));
show_sup = new Button(usercomp, SWT.CHECK);
show_sup.setText(Messages.getString("WizardDefaultsTab.0")); //$NON-NLS-1$
show_sup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
show_oth = new Button(usercomp, SWT.CHECK);
show_oth.setText(Messages.getString("WizardDefaultsTab.1")); //$NON-NLS-1$
show_oth.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label l = new Label(usercomp, SWT.WRAP);
l.setText("\n This checkbox will be moved to another page soon"); //$NON-NLS-1$
l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
show_mng = new Button(usercomp, SWT.CHECK);
show_mng.setText(Messages.getString("WizardDefaultsTab.2")); //$NON-NLS-1$
show_mng.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
protected void performOK() {
CDTPrefUtil.setBool(CDTPrefUtil.KEY_UNSUPP, !show_sup.getSelection());
CDTPrefUtil.setBool(CDTPrefUtil.KEY_OTHERS, show_oth.getSelection());
CDTPrefUtil.setBool(CDTPrefUtil.KEY_MANAGE, show_mng.getSelection());
}
protected void performApply(ICResourceDescription src, ICResourceDescription dst) { performOK(); }
protected void performDefaults() {
show_sup.setSelection(true);
show_oth.setSelection(false);
show_mng.setSelection(false);
}
protected void updateData(ICResourceDescription cfg) {
show_sup.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_UNSUPP));
show_oth.setSelection(CDTPrefUtil.getBool(CDTPrefUtil.KEY_OTHERS));
show_mng.setSelection(CDTPrefUtil.getBool(CDTPrefUtil.KEY_MANAGE));
}
}

View file

@ -70,3 +70,6 @@ BuildAllAction.6=Select configurations to build
BuildAllAction.7=Build configurations
PrefPage_NewCDTWizard.0=Settings will be applied to CDT new project wizard
PrefPage_NewCDTWizard.1=\nduring project creation process
WizardDefaultsTab.0=Show only supported toolchains, by default
WizardDefaultsTab.1=Group old-style toolchains to <Others> folder
WizardDefaultsTab.2=Show <Manage> button on property pages

View file

@ -12,11 +12,12 @@ package org.eclipse.cdt.managedbuilder.ui.wizards;
import java.util.ArrayList;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.ui.newui.ManagedBuilderUIImages;
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
@ -38,6 +39,7 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.dialogs.PreferencesUtil;
public class CConfigWizardPage extends MBSCustomPage {
@ -47,28 +49,27 @@ public class CConfigWizardPage extends MBSCustomPage {
private static final String TITLE = IDEWorkbenchMessages.getString("CConfigWizardPage.0"); //$NON-NLS-1$
private static final String MESSAGE = IDEWorkbenchMessages.getString("CConfigWizardPage.1"); //$NON-NLS-1$
private static final String COMMENT = IDEWorkbenchMessages.getString("CConfigWizardPage.12"); //$NON-NLS-1$
private static final String DELIMITER = "_with_"; //$NON-NLS-1$
private static final String EMPTY_STR = ""; //$NON-NLS-1$
ICWizardHandler handler;
Table table;
CheckboxTableViewer tv;
Label l_projtype;
Label l_chains;
private ICWizardHandler handler;
private Table table;
private CheckboxTableViewer tv;
private Label l_projtype;
private Label l_chains;
private Composite parent;
Composite parent;
String errorMessage = null;
String message = MESSAGE;
private String propertyId;
private String errorMessage = null;
private String message = MESSAGE;
boolean isVisible = false;
Button propButton;
public CConfigWizardPage() { pageID = PAGE_ID; }
private CfgItem[] getCfgItems(boolean getDefault) {
public CfgHolder[] getCfgItems(boolean getDefault) {
if (handler == null) return null;
CfgItem[] its;
CfgHolder[] its;
if (getDefault)
its = cfgItems(getDefaultCfgs(handler));
its = getDefaultCfgs(handler);
else {
ArrayList out = new ArrayList(table.getItemCount());
TableItem[] tis = table.getItems();
@ -76,27 +77,11 @@ public class CConfigWizardPage extends MBSCustomPage {
if (tis[i].getChecked())
out.add(tis[i].getData());
}
its = (CfgItem[])out.toArray(new CfgItem[out.size()]);
its = (CfgHolder[])out.toArray(new CfgHolder[out.size()]);
}
return its;
}
public IConfiguration[] getConfigurations(boolean getDefault) {
CfgItem[] its = getCfgItems(getDefault);
if (its == null) return new IConfiguration[0];
IConfiguration[] cfgs = new IConfiguration[its.length];
for (int i=0; i<its.length; i++) cfgs[i] = its[i].cfg;
return cfgs;
}
public String[] getNames(boolean getDefault) {
CfgItem[] its = getCfgItems(getDefault);
if (its == null) return new String[0];
String [] names = new String[its.length];
for (int i=0; i<its.length; i++) names[i] = its[i].name;
return names;
}
public void createControl(Composite p) {
parent = new Composite(p, SWT.NONE);
parent.setLayoutData(new GridData(GridData.FILL_BOTH));
@ -123,7 +108,7 @@ public class CConfigWizardPage extends MBSCustomPage {
});
tv.setLabelProvider(new LabelProvider() {
public String getText(Object element) {
return element == null ? EMPTY_STR : ((CfgItem)element).name;
return element == null ? EMPTY_STR : ((CfgHolder)element).name;
}
public Image getImage(Object element) { return IMG; }
});
@ -155,16 +140,18 @@ public class CConfigWizardPage extends MBSCustomPage {
isCustomPageComplete();
update();
}});
propButton = new Button(parent, SWT.CHECK);
gd = new GridData(GridData.BEGINNING);
gd.horizontalSpan = 3;
propButton.setLayoutData(gd);
propButton.setText(IDEWorkbenchMessages.getString("CConfigWizardPage.9")); //$NON-NLS-1$
propButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
handler.setShowProperties(((Button)e.widget).getSelection());
}});
// dummy placeholder
new Label(c, 0).setLayoutData(new GridData(GridData.FILL_BOTH));
Button b3 = new Button(c, SWT.PUSH);
b3.setText(IDEWorkbenchMessages.getString("CConfigWizardPage.13")); //$NON-NLS-1$
b3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
b3.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
advancedDialog();
}});
Group gr = new Group(parent, SWT.NONE);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 3;
@ -179,25 +166,29 @@ public class CConfigWizardPage extends MBSCustomPage {
* @param handler
* @return
*/
static public IConfiguration[] getDefaultCfgs(ICWizardHandler handler) {
static public CfgHolder[] getDefaultCfgs(ICWizardHandler handler) {
IToolChain[] tcs = handler.getSelectedToolChains();
String id = handler.getPropertyId();
IProjectType pt = handler.getProjectType();
ArrayList out = new ArrayList(tcs.length * 2);
for (int i=0; i < tcs.length; i++) {
IConfiguration[] cfgs = null;
CfgHolder[] cfgs = null;
if (id != null)
cfgs = ManagedBuildManager.getExtensionConfigurations(tcs[i], ICWizardHandler.ARTIFACT, id);
cfgs = CfgHolder.cfgs2items(ManagedBuildManager.getExtensionConfigurations(tcs[i], ICWizardHandler.ARTIFACT, id));
else if (pt != null)
cfgs = ManagedBuildManager.getExtensionConfigurations(tcs[i], pt);
cfgs = CfgHolder.cfgs2items(ManagedBuildManager.getExtensionConfigurations(tcs[i], pt));
else { // Create default configuration for StdProject
cfgs = new CfgHolder[1];
cfgs[0] = new CfgHolder(tcs[i], null);
}
if (cfgs == null) return null;
for (int j=0; j<cfgs.length; j++) {
if (cfgs[j].isSystemObject() || (handler.supportedOnly() && !cfgs[j].isSupported())) continue;
if (cfgs[j].isSystem() || (handler.supportedOnly() && !cfgs[j].isSupported())) continue;
out.add(cfgs[j]);
}
}
return (IConfiguration[])out.toArray(new IConfiguration[out.size()]);
return (CfgHolder[])out.toArray(new CfgHolder[out.size()]);
}
/**
@ -231,66 +222,24 @@ public class CConfigWizardPage extends MBSCustomPage {
public void setVisible(boolean visible) {
isVisible = visible;
if (visible && handler != null) {
if (handler.needsConfig()) {
tv.setInput(cfgItems(getDefaultCfgs(handler)));
tv.setAllChecked(true);
String s = EMPTY_STR;
IToolChain[] tc = handler.getSelectedToolChains();
for (int i=0; i < tc.length; i++) {
s = s + tc[i].getName();
if (i < tc.length - 1) s = s + ", "; //$NON-NLS-1$
}
l_chains.setText(s);
l_projtype.setText(handler.getName());
tv.setInput(CfgHolder.unique(getDefaultCfgs(handler)));
tv.setAllChecked(true);
String s = EMPTY_STR;
IToolChain[] tc = handler.getSelectedToolChains();
for (int i=0; i < tc.length; i++) {
s = s + ((tc[i] == null) ?
IDEWorkbenchMessages.getString("StdProjectTypeHandler.0") : //$NON-NLS-1$
tc[i].getName());
if (i < tc.length - 1) s = s + ", "; //$NON-NLS-1$
}
propButton.setSelection(handler.showProperties());
l_chains.setText(s);
l_projtype.setText(handler.getName());
}
parent.setVisible(visible);
if (visible) update();
}
class CfgItem {
String name;
IConfiguration cfg;
CfgItem(IConfiguration _cfg) {
cfg = _cfg;
name = cfg.getName();
}
}
private boolean hasDoubles(CfgItem[] its) {
for (int i=0; i<its.length; i++) {
String s = its[i].name;
for (int j=0; j<its.length; j++) {
if (i == j) continue;
if (s.equals(its[j].name))
return true;
}
}
return false;
}
private CfgItem[] cfgItems(IConfiguration[] cfgs) {
CfgItem[] its = new CfgItem[cfgs.length];
for (int i=0; i<cfgs.length; i++)
its[i] = new CfgItem(cfgs[i]);
// if names are not unique, add toolchain name
if (hasDoubles(its)) {
for (int k=0; k<its.length; k++) {
its[k].name = its[k].name + DELIMITER + its[k].cfg.getToolChain().getName();
}
}
// if names are still not unique, add index
if (hasDoubles(its)) {
for (int k=0; k<its.length; k++) {
its[k].name = its[k].name + k;
}
}
return its;
}
//------------------------
//------------------------
private Label setupLabel(Composite c, String name, int span, int mode) {
Label l = new Label(c, SWT.NONE);
l.setText(name);
@ -322,4 +271,25 @@ public class CConfigWizardPage extends MBSCustomPage {
wizard.getContainer().updateMessage();
wizard.getContainer().updateTitleBar();
}
/**
* Edit properties
*/
private void advancedDialog() {
if (wizard instanceof NewModelProjectWizard) {
NewModelProjectWizard nmWizard = (NewModelProjectWizard)wizard;
IProject newProject = nmWizard.getProject(true);
if (newProject != null) {
boolean oldManage = CDTPrefUtil.getBool(CDTPrefUtil.KEY_MANAGE);
// disable manage configurations button
CDTPrefUtil.setBool(CDTPrefUtil.KEY_MANAGE, false);
try {
PreferencesUtil.createPropertyDialogOn(wizard.getContainer().getShell(), newProject, propertyId, null, null).open();
} finally {
CDTPrefUtil.setBool(CDTPrefUtil.KEY_MANAGE, oldManage);
}
}
}
}
}

View file

@ -14,6 +14,7 @@ import java.util.TreeSet;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.ui.newui.PageLayout;
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
@ -50,7 +51,7 @@ import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMes
public class CMainWizardPage extends WizardPage implements IToolChainListListener {
private static final String EXTENSION_POINT_ID = "org.eclipse.cdt.managedbuilder.ui.CDTWizard"; //$NON-NLS-1$
public static final String EXTENSION_POINT_ID = "org.eclipse.cdt.managedbuilder.ui.CDTWizard"; //$NON-NLS-1$
public static final String ELEMENT_NAME = "wizard"; //$NON-NLS-1$
public static final String CLASS_NAME = "class"; //$NON-NLS-1$
@ -65,7 +66,6 @@ import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMes
private Composite right;
private Button show_sup;
private Label right_label;
private Button propButton;
private CConfigWizardPage next;
protected ICWizardHandler h_selected = null;
@ -119,9 +119,9 @@ import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMes
createDynamicGroup(composite);
updateData();
setPageComplete(validatePage());
switchTo(updateData(tree, right, show_sup, CMainWizardPage.this));
setPageComplete(validatePage());
// Show description on opening
setErrorMessage(null);
setMessage(null);
@ -157,7 +157,6 @@ import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMes
right.setLayout(new PageLayout());
show_sup = new Button(c, SWT.CHECK);
show_sup.setSelection(true);
show_sup.setText(org.eclipse.cdt.managedbuilder.ui.wizards.IDEWorkbenchMessages.getString("CMainWizardPage.1")); //$NON-NLS-1$
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
@ -166,27 +165,11 @@ import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMes
public void widgetSelected(SelectionEvent e) {
if (h_selected != null)
h_selected.setSupportedOnly(show_sup.getSelection());
updateData();
switchTo(updateData(tree, right, show_sup, CMainWizardPage.this));
}} );
propButton = new Button(c, SWT.CHECK);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
propButton.setLayoutData(gd);
propButton.setText(org.eclipse.cdt.managedbuilder.ui.wizards.IDEWorkbenchMessages.getString("CMainWizardPage.2")); //$NON-NLS-1$
propButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (h_selected != null)
h_selected.setShowProperties(propButton.getSelection());
}});
}
private void setPropertyCheck(ICWizardHandler h) {
if (h != null) {
propButton.setSelection(h.showProperties());
propButton.setEnabled(true);
} else {
propButton.setEnabled(false);
}
// restore settings from preferences
show_sup.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_UNSUPP));
}
/**
@ -213,14 +196,8 @@ import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMes
public IWizardPage getNextPage() {
if (h_selected == null || h_selected.isDummy()) // cannot continue
return null;
if (h_selected.needsConfig()) { // show config page
MBSCustomPageManager.setPageHideStatus(next.pageID, false);
return next;
} else { // skip config page
MBSCustomPageManager.setPageHideStatus(next.pageID, true);
return MBSCustomPageManager.getNextPage(next.pageID);
}
// MBSCustomPageManager.setPageHideStatus(next.pageID, false);
return next;
}
/**
* Creates the project name specification controls.
@ -264,7 +241,7 @@ import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMes
*
* @return the new project resource handle
*/
public IProject getProjectHandle() {
private IProject getProjectHandle() {
return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName());
}
@ -404,10 +381,7 @@ import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMes
*/
public void setVisible(boolean visible) {
super.setVisible(visible);
setPropertyCheck(h_selected);
if (visible) {
projectNameField.setFocus();
}
if (visible) projectNameField.setFocus();
}
/**
@ -418,7 +392,7 @@ import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMes
return locationArea.isDefault();
}
void updateData() {
public static ICWizardHandler updateData(Tree tree, Composite right, Button show_sup, IToolChainListListener ls) {
// remember selected item
TreeItem[] sel = tree.getSelection();
String savedStr = (sel.length > 0) ? sel[0].getText() : null;
@ -426,9 +400,9 @@ import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMes
tree.removeAll();
IExtensionPoint extensionPoint = Platform.getExtensionRegistry()
.getExtensionPoint(EXTENSION_POINT_ID);
if (extensionPoint == null) return;
if (extensionPoint == null) return null;
IExtension[] extensions = extensionPoint.getExtensions();
if (extensions == null) return;
if (extensions == null) return null;
for (int i = 0; i < extensions.length; ++i) {
IConfigurationElement[] elements = extensions[i].getConfigurationElements();
for (int k = 0; k < elements.length; k++) {
@ -438,11 +412,11 @@ import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMes
w = (ICNewWizard) elements[k].createExecutableExtension(CLASS_NAME);
} catch (CoreException e) {
System.out.println(org.eclipse.cdt.managedbuilder.ui.wizards.IDEWorkbenchMessages.getString("CMainWizardPage.5") + e.getLocalizedMessage()); //$NON-NLS-1$
return;
return null;
}
if (w == null) return;
if (w == null) return null;
w.setDependentControl(right, this);
w.setDependentControl(right, ls);
w.createItems(tree, show_sup.getSelection());
}
}
@ -460,15 +434,15 @@ import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMes
}
}
tree.setSelection(target);
switchTo((ICWizardHandler)target.getData());
return (ICWizardHandler)target.getData();
}
return null;
}
/**
* @param h - new handler
*/
private void switchTo(ICWizardHandler h) {
setPropertyCheck(h);
if (h == null) return;
if (h_selected != null) h_selected.handleUnSelection();
h_selected = h;

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
@ -78,13 +79,18 @@ public class CNewWizard extends AbstractCWizard {
if (tc == null) continue;
h.addTc(tc);
if (oldsRoot == null) {
oldsRoot = new TreeItem(tree, SWT.NONE);
oldsRoot.setText(IDEWorkbenchMessages.getString("CNewWizard.0")); //$NON-NLS-1$
oldsRoot.setData(new DummyHandler(parent));
oldsRoot.setImage(IMG0);
TreeItem ti = null;
if (CDTPrefUtil.getBool(CDTPrefUtil.KEY_OTHERS)) {
if (oldsRoot == null) {
oldsRoot = new TreeItem(tree, SWT.NONE);
oldsRoot.setText(IDEWorkbenchMessages.getString("CNewWizard.0")); //$NON-NLS-1$
oldsRoot.setData(new DummyHandler(parent));
oldsRoot.setImage(IMG0);
}
ti = new TreeItem(oldsRoot, SWT.NONE);
} else { // do not group to <Others>
ti = new TreeItem(tree, SWT.NONE);
}
TreeItem ti = new TreeItem(oldsRoot, SWT.NONE);
ti.setText(h.getName());
ti.setData(h);
ti.setImage(h.getIcon());

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.managedbuilder.ui.wizards;
import java.util.Iterator;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
@ -27,8 +28,13 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
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.ui.newui.ManagedBuilderUIImages;
import org.eclipse.cdt.managedbuilder.ui.newui.ManagedBuilderUIPlugin;
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@ -46,8 +52,11 @@ import org.eclipse.swt.widgets.TableItem;
*
*/
public class CWizardHandler implements ICWizardHandler {
static final private String head = IDEWorkbenchMessages.getString("CWizardHandler.0"); //$NON-NLS-1$
static final private String tooltip =
private static final Image IMG0 = ManagedBuilderUIImages.get(ManagedBuilderUIImages.IMG_EMPTY);
private static final Image IMG1 = ManagedBuilderUIImages.get(ManagedBuilderUIImages.IMG_PREFERRED);
private static final String head = IDEWorkbenchMessages.getString("CWizardHandler.0"); //$NON-NLS-1$
private static final String tooltip =
IDEWorkbenchMessages.getString("CWizardHandler.1")+ //$NON-NLS-1$
IDEWorkbenchMessages.getString("CWizardHandler.2") + //$NON-NLS-1$
IDEWorkbenchMessages.getString("CWizardHandler.3") + //$NON-NLS-1$
@ -58,10 +67,9 @@ public class CWizardHandler implements ICWizardHandler {
private String name;
private Image image;
private Composite parent;
private Table table;
protected Table table;
private String propertyId = null;
private IProjectType pt = null;
private boolean showProps = false;
private IToolChainListListener listener;
private boolean supportedOnly = true;
@ -84,24 +92,33 @@ public class CWizardHandler implements ICWizardHandler {
}
public void handleSelection() {
List preferred = CDTPrefUtil.getPreferredTCs();
if (table == null) {
table = new Table(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
table.setToolTipText(tooltip);
Iterator it = 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);
String id = CDTPrefUtil.NULL;
if (obj instanceof IToolChain) {
IToolChain tc = (IToolChain)obj;
String name = tc.getUniqueRealName();
id = tc.getId();
//TODO: add version
ti.setText(tc.getUniqueRealName());
ti.setText(name);
ti.setData(tc);
} else {
} else { // NULL for -NO TOOLCHAIN-
ti.setText(s);
}
if (position == 0 && preferred.contains(id)) position = counter;
counter++;
}
if (tcs.size() > 0) table.select(0);
if (tcs.size() > 0) table.select(position);
table.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
@ -109,6 +126,7 @@ public class CWizardHandler implements ICWizardHandler {
listener.toolChainListChanged(table.getSelectionCount());
}});
}
updatePreferred(preferred);
table.setVisible(true);
parent.layout();
}
@ -145,21 +163,29 @@ public class CWizardHandler implements ICWizardHandler {
}
}
public void createProject(IProject project, IConfiguration[] cfgs, String[] names) throws CoreException {
public void createProject(IProject project, CfgHolder[] cfgs) throws CoreException {
CoreModel coreModel = CoreModel.getDefault();
ICProjectDescription des = coreModel.getProjectDescription(project);
des = coreModel.createProjectDescription(project, true);
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
if (cfgs == null || cfgs.length == 0)
if (cfgs == null || cfgs.length == 0)
cfgs = CConfigWizardPage.getDefaultCfgs(this);
ManagedProject mProj = new ManagedProject(project, cfgs[0].getProjectType());
if (cfgs[0].cfg == null) {
throw new CoreException(new Status(IStatus.ERROR,
ManagedBuilderUIPlugin.getUniqueIdentifier(),
IDEWorkbenchMessages.getString("CWizardHandler.6"))); //$NON-NLS-1$
}
ManagedProject mProj = new ManagedProject(project, cfgs[0].cfg.getProjectType());
info.setManagedProject(mProj);
cfgs = CfgHolder.unique(cfgs);
for(int i = 0; i < cfgs.length; i++){
String id = ManagedBuildManager.calculateChildId(cfgs[i].getId(), null);
Configuration config = new Configuration(mProj, (Configuration)cfgs[i], id, false, true);
String id = ManagedBuildManager.calculateChildId(cfgs[i].cfg.getId(), null);
Configuration config = new Configuration(mProj, (Configuration)cfgs[i].cfg, id, false, true);
CConfigurationData data = config.getConfigurationData();
ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
config.setConfigurationDescription(cfgDes);
@ -169,7 +195,7 @@ public class CWizardHandler implements ICWizardHandler {
if (bld != null) { bld.setManagedBuildOn(true); }
String s = project.getName();
config.setName(names[i]);
config.setName(cfgs[i].name);
config.setArtifactName(s);
}
coreModel.setProjectDescription(project, des);
@ -181,15 +207,25 @@ public class CWizardHandler implements ICWizardHandler {
public String getName() { return name; }
public Image getIcon() { return image; }
public boolean isDummy() { return false; }
public boolean needsConfig() { return true; }
public int getToolChainsCount() { return tcs.size(); }
public void setShowProperties(boolean show) { showProps = show; }
public boolean showProperties() { return showProps; }
public IProjectType getProjectType() { return pt; }
public String getPropertyId() { return propertyId; }
public boolean canCreateWithoutToolchain() { return false; }
public void setSupportedOnly(boolean supp) { supportedOnly = supp;}
public boolean supportedOnly() { return supportedOnly; }
public boolean supportsPreferred() { return true; }
/**
* Mark preferred toolchains with specific images
*/
public void updatePreferred(List prefs) {
int x = table.getItemCount();
for (int i=0; i<x; i++) {
TableItem ti = table.getItem(i);
IToolChain tc = (IToolChain)ti.getData();
String id = (tc == null) ? CDTPrefUtil.NULL : tc.getId();
ti.setImage( prefs.contains(id) ? IMG1 : IMG0);
}
}
}

View file

@ -0,0 +1,96 @@
/*******************************************************************************
* 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.managedbuilder.ui.wizards;
import java.util.ArrayList;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
/*
* This class is intended for data exchange between
* Configuration page and Handlers.
* It may hold configuration in case of managed project
* or to be a placeholder in case of make project
*/
public class CfgHolder {
private static final String DELIMITER = "_with_"; //$NON-NLS-1$
String name;
IConfiguration cfg;
IToolChain tc;
public CfgHolder(IToolChain _tc, IConfiguration _cfg) {
tc = _tc;
cfg = _cfg;
if (cfg == null) {
if (tc == null)
name = IDEWorkbenchMessages.getString("StdProjectTypeHandler.2"); //$NON-NLS-1$
else
name = tc.getName();
} else
name = cfg.getName();
}
public boolean isSystem() {
if (cfg == null) return false;
return (cfg.isSystemObject());
}
public boolean isSupported() {
if (cfg == null) return true;
return (cfg.isSupported());
}
public static boolean hasDoubles(CfgHolder[] its) {
for (int i=0; i<its.length; i++) {
String s = its[i].name;
for (int j=0; j<its.length; j++) {
if (i == j) continue;
if (s.equals(its[j].name))
return true;
}
}
return false;
}
public static CfgHolder[] cfgs2items(IConfiguration[] cfgs) {
CfgHolder[] its = new CfgHolder[cfgs.length];
for (int i=0; i<cfgs.length; i++) {
its[i] = new CfgHolder(cfgs[i].getToolChain(), cfgs[i]);
}
return its;
}
public static CfgHolder[] unique(CfgHolder[] its) {
// if names are not unique, add toolchain name
if (hasDoubles(its)) {
for (int k=0; k<its.length; k++) {
its[k].name = its[k].name + DELIMITER + its[k].cfg.getToolChain().getName();
}
}
// if names are still not unique, add index
if (hasDoubles(its)) {
for (int k=0; k<its.length; k++) {
its[k].name = its[k].name + k;
}
}
return its;
}
/*
* Note that null configurations are ignored !
*/
public static IConfiguration[] items2cfgs(CfgHolder[] its) {
ArrayList lst = new ArrayList(its.length);
for (int i=0; i<its.length; i++)
if (its[i].cfg != null) lst.add(its[i].cfg);
return (IConfiguration[])lst.toArray(new IConfiguration[lst.size()]);
}
}

View file

@ -10,7 +10,8 @@
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.ui.wizards;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import java.util.List;
import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.core.resources.IProject;
@ -42,7 +43,7 @@ public class DummyHandler implements ICWizardHandler {
public void handleSelection() {}
public void handleUnSelection() {}
public IWizardPage getNextPage() { return null; }
public void createProject(IProject project, IConfiguration[] cfgs, String[] names) throws CoreException {}
public void createProject(IProject project, CfgHolder[] cfgs) throws CoreException {}
public boolean isDummy() { return true; }
public boolean needsConfig() { return false; }
public IToolChain[] getSelectedToolChains() {return null;}
@ -54,5 +55,7 @@ public class DummyHandler implements ICWizardHandler {
public boolean canCreateWithoutToolchain() { return false; }
public void setSupportedOnly(boolean supp) {}
public boolean supportedOnly() { return true; }
public boolean isFirstPageSelected() { return false; }
public boolean isFirstPageSelected() { return false; }
public boolean supportsPreferred() {return false; }
public void updatePreferred(List prefs) {}
}

View file

@ -10,7 +10,8 @@
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.ui.wizards;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import java.util.List;
import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.core.resources.IProject;
@ -26,21 +27,34 @@ public interface ICWizardHandler {
String getName();
Image getIcon();
String getHeader();
void createProject(IProject proj, IConfiguration[] cfgs, String[] names) throws CoreException;
void createProject(IProject proj, CfgHolder[] cfgs) throws CoreException;
boolean isDummy();
boolean needsConfig();
public IToolChain[] getSelectedToolChains();
public int getToolChainsCount();
public IProjectType getProjectType();
public void setShowProperties(boolean show);
public boolean showProperties();
public String getPropertyId();
/**
* @return true if only supported project types and toolchains are displayed
*/
public boolean supportedOnly();
/**
* Defines whether only supported project types and toolchains are displayed
* @param supp
*/
public void setSupportedOnly(boolean supp);
/**
* @return true if project can be created with zero toolchains selected
*/
public boolean canCreateWithoutToolchain();
/**
* @return true if handler is able to process preferred toolchains
*/
public boolean supportsPreferred();
/**
* Asks handler to update its data according to preferred list.
* Usually, marks preferred toolchains somehow (icon, font etc)
* @param prefs - list of strings (preferred Toolchain IDs)
*/
public void updatePreferred(List prefs);
}

View file

@ -18,12 +18,13 @@ import java.util.Set;
import java.util.TreeSet;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.ui.newui.ManagedBuilderUIPlugin;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.newui.NewUIMessages;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
@ -37,29 +38,19 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
public abstract class NewModelProjectWizard extends BasicNewResourceWizard implements IExecutableExtension
//extends NewManagedProjectWizard
{
private static final String MSG_CREATE = "MngCCWizard.message.creating"; //$NON-NLS-1$
private static final String PREFIX= "CProjectWizard"; //$NON-NLS-1$
private static final String OP_ERROR= "CProjectWizard.op_error"; //$NON-NLS-1$
private static final String OP_DESC= "CProjectWizard.op_description"; //$NON-NLS-1$
private static final String title= CUIPlugin.getResourceString(OP_ERROR + ".title"); //$NON-NLS-1$
private static final String message= CUIPlugin.getResourceString(OP_ERROR + ".message"); //$NON-NLS-1$
protected IConfigurationElement fConfigElement;
protected CMainWizardPage fMainPage;
@ -68,7 +59,11 @@ public abstract class NewModelProjectWizard extends BasicNewResourceWizard imple
protected IProject newProject;
private String wz_title;
private String wz_desc;
private String propertyId;
private String lastProjectName = null;
private ICWizardHandler savedHandler = null;
private IToolChain[] savedToolChains = null;
private boolean savedDefaults = false;
protected List localPages = new ArrayList(); // replacing Wizard.pages since we have to delete them
@ -122,50 +117,61 @@ public abstract class NewModelProjectWizard extends BasicNewResourceWizard imple
}
}
protected void doRun(IProgressMonitor monitor) throws CoreException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask(NewUIMessages.getResourceString(MSG_CREATE), 8);
newProject = createIProject(fMainPage.getProjectName(), fMainPage.getProjectLocation());
if (newProject != null) {
try {
if (fMainPage.h_selected.needsConfig()) {
boolean def = fMainPage.isCurrent();
fMainPage.h_selected.createProject(newProject, fConfigPage.getConfigurations(def), fConfigPage.getNames(def));
} else
fMainPage.h_selected.createProject(newProject, null, null);
} catch (CoreException e) {
ManagedBuilderUIPlugin.log(e);
throw e;
/**
* @return true if user has changed settings since project creation
*/
private boolean isChanged() {
if (savedHandler != fMainPage.h_selected || !fMainPage.getProjectName().equals(lastProjectName))
return true;
IToolChain[] tcs = fMainPage.h_selected.getSelectedToolChains();
if (savedToolChains.length != tcs.length)
return true;
for (int i=0; i<savedToolChains.length; i++) {
boolean found = false;
for (int j=0; i<tcs.length; j++) {
if (savedToolChains[i] == tcs[j]) {
found = true; break;
}
}
if (!found) return true;
}
monitor.done();
return false;
}
public IProject getProject(boolean defaults) {
if (newProject != null && isChanged())
clearProject();
if (newProject == null) {
savedDefaults = defaults;
savedHandler = fMainPage.h_selected;
savedToolChains = fMainPage.h_selected.getSelectedToolChains();
lastProjectName = fMainPage.getProjectName();
// start creation process
invokeRunnable(getRunnable(defaults));
}
return newProject;
}
protected IProject getProjectHandle() throws UnsupportedOperationException {
if (null == fMainPage)
throw new UnsupportedOperationException();
return fMainPage.getProjectHandle();
/**
* Remove created project either after error
* or if user returned back from config page.
*/
public void clearProject() {
if (lastProjectName == null) return;
try {
ResourcesPlugin.getWorkspace().getRoot().getProject(lastProjectName).delete(false, false, null);
} catch (CoreException ignore) {}
newProject = null;
lastProjectName = null;
}
protected boolean invokeRunnable(IRunnableWithProgress runnable) {
private boolean invokeRunnable(IRunnableWithProgress runnable) {
IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(runnable);
try {
getContainer().run(true, true, op);
} catch (InvocationTargetException e) {
Shell shell= getShell();
String title= CUIPlugin.getResourceString(OP_ERROR + ".title"); //$NON-NLS-1$
String message= CUIPlugin.getResourceString(OP_ERROR + ".message"); //$NON-NLS-1$
Throwable th= e.getTargetException();
CUIPlugin.errorDialog(shell, title, message, th, false);
try {
getProjectHandle().delete(false, false, null);
} catch (CoreException ignore) {
} catch (UnsupportedOperationException ignore) {
}
CUIPlugin.errorDialog(getShell(), title, message, e.getTargetException(), false);
clearProject();
return false;
} catch (InterruptedException e) {
return false;
@ -174,117 +180,81 @@ public abstract class NewModelProjectWizard extends BasicNewResourceWizard imple
}
public boolean performFinish() {
if (!invokeRunnable(getRunnable())) {
return false;
}
// needs delete only if project was
// created before and still valid
boolean needsDelete = (newProject != null && savedDefaults && !isChanged());
// create project if it is not created yet
if (getProject(false) == null) return false;
// process custom pages
doCustom();
// project is created with all possible configs
// to let user modify all of them. Resulting
// project should contain only selected cfgs.
if (needsDelete) deleteExtraConfigs();
BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
IResource resource = newProject;
selectAndReveal(resource);
if (resource != null && resource.getType() == IResource.FILE) {
IFile file = (IFile)resource;
// Open editor on new file.
IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow();
if (dw != null) {
try {
IWorkbenchPage page = dw.getActivePage();
if (page != null)
IDE.openEditor(page, file, true);
} catch (PartInitException e) {
MessageDialog.openError(dw.getShell(),
CUIPlugin.getResourceString(OP_ERROR), e.getMessage());
}
}
}
// run properties dialog if required
if (fMainPage.h_selected.showProperties())
PreferencesUtil.createPropertyDialogOn(getShell(), newProject, propertyId, null, null).open();
selectAndReveal(newProject);
return true;
}
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
fConfigElement= config;
private void deleteExtraConfigs() {
if (fMainPage.isCurrent()) return; // nothing to delete
ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(newProject, true);
if (prjd == null) return;
ICConfigurationDescription[] all = prjd.getConfigurations();
if (all == null) return;
CfgHolder[] req = fConfigPage.getCfgItems(false);
boolean modified = false;
for (int i=0; i<all.length; i++) {
boolean found = false;
for (int j=0; j<req.length; j++) {
if (all[i].getName() == req[j].name) {
found = true; break;
}
}
if (!found) {
modified = true;
prjd.removeConfiguration(all[i]);
}
}
if (modified) try {
CoreModel.getDefault().setProjectDescription(newProject, prjd);
} catch (CoreException e) {}
}
public IRunnableWithProgress getRunnable() {
return new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {
public void run(IProgressMonitor imonitor) throws InvocationTargetException, InterruptedException {
final Exception except[] = new Exception[1];
// ugly, need to make the wizard page run in a non ui thread so that this can go away!!!
getShell().getDisplay().syncExec(new Runnable() {
public void run() {
IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
final IProgressMonitor fMonitor;
if (monitor == null) {
fMonitor= new NullProgressMonitor();
} else {
fMonitor = monitor;
}
fMonitor.beginTask(CUIPlugin.getResourceString(OP_DESC), 3);
doRunPrologue(new SubProgressMonitor(fMonitor, 1));
try {
doRun(new SubProgressMonitor(fMonitor, 1));
}
catch (CoreException e) {
except[0] = e;
}
doRunEpilogue(new SubProgressMonitor(fMonitor, 1));
fMonitor.done();
}
});
try {
getContainer().run(false, true, op);
} catch (InvocationTargetException e) {
except[0] = e;
} catch (InterruptedException e) {
except[0] = e;
}
}
});
if (except[0] != null) {
if (except[0] instanceof InvocationTargetException) {
throw (InvocationTargetException)except[0];
}
if (except[0] instanceof InterruptedException) {
throw (InterruptedException)except[0];
}
throw new InvocationTargetException(except[0]);
}
}
});
}
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.wizards.NewCProjectWizard#doRunPrologue(org.eclipse.core.runtime.IProgressMonitor)
*/
protected void doRunPrologue(IProgressMonitor monitor) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.wizards.NewCProjectWizard#doRunEpilogue(org.eclipse.core.runtime.IProgressMonitor)
*/
protected void doRunEpilogue(IProgressMonitor monitor) {
if(newProject == null) return;
IStatus initResult = ManagedBuildManager.initBuildInfoContainer(newProject);
if (initResult.getCode() != IStatus.OK) {
ManagedBuilderUIPlugin.log(initResult);
}
// execute any operations specified by custom pages
private void doCustom() {
Runnable operations[] = MBSCustomPageManager.getOperations();
if(operations != null)
for(int k = 0; k < operations.length; k++)
operations[k].run();
}
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
fConfigElement= config;
}
private IRunnableWithProgress getRunnable(boolean _defaults) {
final boolean defaults = _defaults;
return new IRunnableWithProgress() {
public void run(IProgressMonitor imonitor) throws InvocationTargetException, InterruptedException {
getShell().getDisplay().syncExec(new Runnable() {
public void run() {
try {
newProject = createIProject(lastProjectName, fMainPage.getProjectLocation());
if (newProject != null)
fMainPage.h_selected.createProject(newProject, fConfigPage.getCfgItems(defaults));
} catch (CoreException e) { ManagedBuilderUIPlugin.log(e); }
}
});
}
};
}
/**
*
*/
public IProject createIProject(final String name, final IPath location) throws CoreException{
if (newProject != null)
return newProject;
if (newProject != null) return newProject;
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
@ -317,5 +287,5 @@ public abstract class NewModelProjectWizard extends BasicNewResourceWizard imple
}
protected abstract IProject continueCreation(IProject prj);
protected abstract String[] getNatures();
protected abstract String[] getNatures();
}

View file

@ -45,11 +45,7 @@ public class StdProjectTypeHandler extends CWizardHandler {
/**
* Note that configurations parameter is ignored
*/
public void createProject(IProject project, IConfiguration[] cfgs, String[] names) throws CoreException {
IToolChain[] tcs = getSelectedToolChains();
if (tcs == null || tcs.length == 0) {
tcs = new IToolChain[1]; // null value
}
public void createProject(IProject project, CfgHolder[] cfgs) throws CoreException {
CoreModel coreModel = CoreModel.getDefault();
ICProjectDescription des = coreModel.getProjectDescription(project);
des = coreModel.createProjectDescription(project, true);
@ -57,15 +53,9 @@ public class StdProjectTypeHandler extends CWizardHandler {
ManagedProject mProj = new ManagedProject(des);
info.setManagedProject(mProj);
for (int i=0; i<tcs.length; i++) {
String s = "0"; //$NON-NLS-1$
String name = IDEWorkbenchMessages.getString("StdProjectTypeHandler.2"); //$NON-NLS-1$
if (tcs[i] != null) {
s = tcs[i].getId();
name = tcs[i].getName();
}
Configuration cfg = new Configuration(mProj, (ToolChain)tcs[i], ManagedBuildManager.calculateChildId(s, null), name);
for (int i=0; i<cfgs.length; i++) {
String s = (cfgs[i].tc == null) ? "0" : cfgs[i].tc.getId(); //$NON-NLS-1$
Configuration cfg = new Configuration(mProj, (ToolChain)cfgs[i].tc, ManagedBuildManager.calculateChildId(s, null), cfgs[i].name);
IBuilder bld = cfg.getEditableBuilder();
if (bld != null) {
if(bld.isInternalBuilder()){
@ -85,7 +75,16 @@ public class StdProjectTypeHandler extends CWizardHandler {
}
coreModel.setProjectDescription(project, des);
}
public boolean needsConfig() { return false; }
public boolean canCreateWithoutToolchain() { return true; }
/**
* If no toolchains selected by user, use default toolchain
*/
public IToolChain[] getSelectedToolChains() {
if (tcs.size() == 0 || table.getSelection().length == 0)
return new IToolChain[] { null };
else
return super.getSelectedToolChains();
}
}

View file

@ -12,6 +12,7 @@ CConfigWizardPage.9=Edit properties after project creation
CConfigWizardPage.10=At least one configuration should be available. Project cannot be created.
CConfigWizardPage.11=At least one configuration should be selected. Please check needed configurations.
CConfigWizardPage.12=Additional configurations can be added after project creation.\nUse "Manage configurations" buttons either on toolbar or on property pages.
CConfigWizardPage.13=Advanced settings...
CMainWizardPage.0=Project types:
CMainWizardPage.1=Show project types and toolchains only if they are supported on the platform
CMainWizardPage.2=Edit properties after project creation
@ -28,6 +29,7 @@ CWizardHandler.2=(compiler, linker, assembler)\n
CWizardHandler.3=intended to build your project.\n
CWizardHandler.4=Additional tools, like debugger,\n
CWizardHandler.5=can be assotiated with tool chain.
CWizardHandler.6=Cannot create managed project with NULL configuration
NewModelProjectWizard.0=CDT project (exprimental)
NewModelProjectWizard.1=Create CDT project of selected type
NewModelProjectWizard.2=C++ project (exprimental)
@ -35,3 +37,6 @@ NewModelProjectWizard.3=Create C++ project of selected type
NewModelProjectWizard.4=C project (exprimental)
NewModelProjectWizard.5=Create C project of selected type
StdBuildWizard.0=Makefile project
PreferredToolchainsTab.0=Preferred toolchain will be selected by default in Wizard
PreferredToolchainsTab.1=Make toolhain(s) preferred
PreferredToolchainsTab.2=Make toolhain(s) unpreferred