mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 09:16:02 +02:00
Apply patch from 110423; add setSelectProjectType to se default project type in new project wizard
This commit is contained in:
parent
4075cacd7d
commit
bdd3de47b7
4 changed files with 180 additions and 2 deletions
|
@ -0,0 +1,118 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2005 Innoopract Informationssysteme GmbH 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:
|
||||||
|
* Innoopract - Initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.managedbuilder.ui.tests;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.managedbuilder.core.IProjectType;
|
||||||
|
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||||
|
import org.eclipse.cdt.managedbuilder.ui.wizards.CProjectPlatformPage;
|
||||||
|
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
|
||||||
|
import org.eclipse.cdt.managedbuilder.ui.wizards.NewManagedProjectWizard;
|
||||||
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
import org.eclipse.ui.PlatformUI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for the get/setSelectedProjectType() of CProjectPlatformPage.
|
||||||
|
* @author Elias Volanakis
|
||||||
|
*/
|
||||||
|
public class TestCProjectPlatformPage extends TestCase {
|
||||||
|
|
||||||
|
private NewManagedProjectWizard wizard;
|
||||||
|
private TestPage page;
|
||||||
|
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
MBSCustomPageManager.init();
|
||||||
|
MBSCustomPageManager.loadExtensions();
|
||||||
|
wizard = new NewManagedProjectWizard();
|
||||||
|
page = new TestPage(wizard);
|
||||||
|
wizard.addPages();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
page.dispose();
|
||||||
|
page = null;
|
||||||
|
wizard = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// testing methods
|
||||||
|
//////////////////
|
||||||
|
|
||||||
|
/* Test the new page, set selection, create page lifecycle. */
|
||||||
|
public void testSelectedProjectType1() throws Exception {
|
||||||
|
page.createControl(getShell());
|
||||||
|
final IProjectType type2 = page.getSecondType();
|
||||||
|
|
||||||
|
TestPage page2 = new TestPage(wizard);
|
||||||
|
page2.setSelectedProjectType(type2);
|
||||||
|
page2.createControl(getShell());
|
||||||
|
assertEquals(type2, page2.getSelectedProjectType());
|
||||||
|
page2.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test the new page, create page, set selection lifecycle. */
|
||||||
|
public void testSelectedProjectType2() throws Exception {
|
||||||
|
// test get null
|
||||||
|
assertNull(page.getSelectedProjectType());
|
||||||
|
// test set null
|
||||||
|
page.setSelectedProjectType(null);
|
||||||
|
assertNull(page.getSelectedProjectType()); // null, since no UI created
|
||||||
|
|
||||||
|
// create ui
|
||||||
|
page.createControl(getShell());
|
||||||
|
final IProjectType type1 = page.getFirstType();
|
||||||
|
|
||||||
|
// default behavior if selection set to null -> select first item
|
||||||
|
assertEquals(type1, page.getSelectedProjectType());
|
||||||
|
// set 2nd element from project types list
|
||||||
|
final IProjectType type2 = page.getSecondType();
|
||||||
|
assertNotNull(type2);
|
||||||
|
page.setSelectedProjectType(type2);
|
||||||
|
assertEquals(type2, page.getSelectedProjectType());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests that setting the selection to a projectType thats not on the list,
|
||||||
|
* is handled correctly.
|
||||||
|
*/
|
||||||
|
public void testSelectedProjectType3() throws Exception {
|
||||||
|
IProjectType testType = ManagedBuildManager.getProjectType("cdt.managedbuild.target.testgnu21.so");
|
||||||
|
assertNotNull(testType);
|
||||||
|
assertTrue(testType.isTestProjectType());
|
||||||
|
page.setSelectedProjectType(testType);
|
||||||
|
page.createControl(getShell());
|
||||||
|
// no selection made
|
||||||
|
assertNull(null,page.getSelectedProjectType());
|
||||||
|
assertFalse(page.canFlipToNextPage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// helping methods and classes
|
||||||
|
//////////////////////////////
|
||||||
|
|
||||||
|
private Shell getShell() {
|
||||||
|
return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestPage extends CProjectPlatformPage {
|
||||||
|
TestPage(NewManagedProjectWizard wizard) throws Exception {
|
||||||
|
super(TestCProjectPlatformPage.class.getName(), wizard);
|
||||||
|
}
|
||||||
|
IProjectType getFirstType() {
|
||||||
|
return (IProjectType) projectTypes.get(0);
|
||||||
|
}
|
||||||
|
IProjectType getSecondType() {
|
||||||
|
return (IProjectType) projectTypes.get(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -11,6 +11,7 @@
|
||||||
package org.eclipse.cdt.managedbuilder.ui.tests.suite;
|
package org.eclipse.cdt.managedbuilder.ui.tests.suite;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.managedbuilder.ui.tests.TestCProjectPlatformPage;
|
||||||
import org.eclipse.cdt.managedbuilder.ui.tests.TestCustomPageManager;
|
import org.eclipse.cdt.managedbuilder.ui.tests.TestCustomPageManager;
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ public class AllManagedBuildUITests {
|
||||||
//$JUnit-BEGIN$
|
//$JUnit-BEGIN$
|
||||||
// TODO uncoment this
|
// TODO uncoment this
|
||||||
suite.addTest(TestCustomPageManager.suite());
|
suite.addTest(TestCustomPageManager.suite());
|
||||||
|
suite.addTestSuite(TestCProjectPlatformPage.class);
|
||||||
|
|
||||||
//$JUnit-END$
|
//$JUnit-END$
|
||||||
return suite;
|
return suite;
|
||||||
|
|
|
@ -23,9 +23,12 @@ import org.eclipse.cdt.managedbuilder.core.IToolChain;
|
||||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||||
import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderHelpContextIds;
|
import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderHelpContextIds;
|
||||||
import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIMessages;
|
import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIMessages;
|
||||||
|
import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIPlugin;
|
||||||
import org.eclipse.cdt.ui.wizards.NewCProjectWizard;
|
import org.eclipse.cdt.ui.wizards.NewCProjectWizard;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||||
import org.eclipse.jface.viewers.CheckboxTableViewer;
|
import org.eclipse.jface.viewers.CheckboxTableViewer;
|
||||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||||
|
@ -75,6 +78,7 @@ public class CProjectPlatformPage extends WizardPage {
|
||||||
protected NewManagedProjectWizard parentWizard;
|
protected NewManagedProjectWizard parentWizard;
|
||||||
protected Combo platformSelection;
|
protected Combo platformSelection;
|
||||||
private ArrayList selectedConfigurations;
|
private ArrayList selectedConfigurations;
|
||||||
|
private IProjectType defaultProjectType;
|
||||||
protected IProjectType selectedProjectType;
|
protected IProjectType selectedProjectType;
|
||||||
protected Button showAllProjTypes;
|
protected Button showAllProjTypes;
|
||||||
protected Button showAllConfigs;
|
protected Button showAllConfigs;
|
||||||
|
@ -161,8 +165,10 @@ public class CProjectPlatformPage extends WizardPage {
|
||||||
|
|
||||||
// Select the first project type in the list
|
// Select the first project type in the list
|
||||||
populateTypes();
|
populateTypes();
|
||||||
platformSelection.select(0);
|
IProjectType type = (defaultProjectType != null)
|
||||||
handleTypeSelection();
|
? defaultProjectType
|
||||||
|
: (IProjectType) projectTypes.get(0);
|
||||||
|
setProjectType(type);
|
||||||
|
|
||||||
// Do the nasty
|
// Do the nasty
|
||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
|
@ -263,6 +269,41 @@ public class CProjectPlatformPage extends WizardPage {
|
||||||
public IProjectType getSelectedProjectType() {
|
public IProjectType getSelectedProjectType() {
|
||||||
return selectedProjectType;
|
return selectedProjectType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the selected project type.
|
||||||
|
* <p>If createControl(...) has been called, the selection will be set
|
||||||
|
* immediately. Otherwise the selection will be set during the
|
||||||
|
* createControl(...) invocation.
|
||||||
|
* </p>
|
||||||
|
* @param type a IProjectType instance, or <tt>null</tt> to select the
|
||||||
|
* the first available project type
|
||||||
|
* @see #createControl(Composite)
|
||||||
|
*/
|
||||||
|
public void setSelectedProjectType(IProjectType type) {
|
||||||
|
if (projectTypeNames != null && platformSelection != null) {
|
||||||
|
// set project type now
|
||||||
|
setProjectType(type);
|
||||||
|
} else {
|
||||||
|
// set project during createControl(Control)
|
||||||
|
defaultProjectType = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setProjectType(IProjectType type) {
|
||||||
|
String name = (type != null) ? type.getName() : projectTypeNames[0];
|
||||||
|
boolean found = false;
|
||||||
|
for (int i = 0; !found && i < projectTypeNames.length; i++) {
|
||||||
|
if (name.equals(projectTypeNames[i])) {
|
||||||
|
platformSelection.select(i);
|
||||||
|
handleTypeSelection();
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
log("Could not find project-type with name: " + name); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void handleConfigurationSelectionChange() {
|
private void handleConfigurationSelectionChange() {
|
||||||
// Get the selections from the table viewer
|
// Get the selections from the table viewer
|
||||||
|
@ -491,4 +532,10 @@ public class CProjectPlatformPage extends WizardPage {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void log(String msg) {
|
||||||
|
String id = ManagedBuilderUIPlugin.getUniqueIdentifier();
|
||||||
|
IStatus status = new Status(IStatus.WARNING, id, 0, msg, null);
|
||||||
|
ManagedBuilderUIPlugin.log(status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,4 +259,15 @@ public class NewManagedProjectWizard extends NewCProjectWizard {
|
||||||
public IConfiguration[] getSelectedConfigurations() {
|
public IConfiguration[] getSelectedConfigurations() {
|
||||||
return projectConfigurationPage.getSelectedConfigurations();
|
return projectConfigurationPage.getSelectedConfigurations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the selected project type.
|
||||||
|
* <p>The addPages() method must have been invoked, before this method can
|
||||||
|
* be used.</p>
|
||||||
|
* @param type a IProjectType instance, or <tt>null</tt> to select the
|
||||||
|
* the first available project type
|
||||||
|
*/
|
||||||
|
public void setSelectedProjectType(IProjectType type) {
|
||||||
|
projectConfigurationPage.setSelectedProjectType(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue