001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.ui.tests.dialogs;
011:
012: import java.io.IOException;
013: import java.lang.reflect.InvocationTargetException;
014:
015: import junit.framework.Test;
016: import junit.framework.TestCase;
017: import junit.framework.TestSuite;
018:
019: import org.eclipse.core.runtime.CoreException;
020:
021: import org.eclipse.swt.widgets.Shell;
022:
023: import org.eclipse.jface.viewers.ILabelProvider;
024:
025: import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
026: import org.eclipse.ui.dialogs.SelectionDialog;
027:
028: import org.eclipse.jdt.core.IJavaProject;
029: import org.eclipse.jdt.core.IPackageFragmentRoot;
030:
031: import org.eclipse.jdt.ui.IJavaElementSearchConstants;
032: import org.eclipse.jdt.ui.JavaElementComparator;
033: import org.eclipse.jdt.ui.JavaElementLabelProvider;
034: import org.eclipse.jdt.ui.JavaUI;
035: import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
036:
037: import org.eclipse.jdt.testplugin.JavaProjectHelper;
038: import org.eclipse.jdt.testplugin.util.DialogCheck;
039:
040: public class DialogsTest2 extends TestCase {
041:
042: private static final String PROJECT_NAME = "DummyProject";
043:
044: public static Test suite() {
045: TestSuite suite = new TestSuite(DialogsTest2.class.getName());
046: suite
047: .addTest(new DialogsTest2(
048: "testCheckedTreeSelectionDialog"));
049: suite
050: .addTest(new DialogsTest2(
051: "testCheckedTreeSelectionDialog"));
052: suite.addTest(new DialogsTest2("testPackageSelectionDialog01"));
053: suite.addTest(new DialogsTest2("testPackageSelectionDialog02"));
054: return suite;
055: }
056:
057: public DialogsTest2(String name) {
058: super (name);
059: }
060:
061: private Shell getShell() {
062: return DialogCheck.getShell();
063: }
064:
065: public void testCheckedTreeSelectionDialog() throws Exception {
066: IJavaProject jproject = JavaProjectHelper.createJavaProject(
067: PROJECT_NAME, "bin");
068: JavaProjectHelper.addSourceContainer(jproject, "src1");
069: Object initSelection = JavaProjectHelper.addSourceContainer(
070: jproject, "src2");
071:
072: IJavaProject jproject2 = JavaProjectHelper.createJavaProject(
073: "Project2", "bin");
074: JavaProjectHelper.addSourceContainer(jproject2, "src1");
075: JavaProjectHelper.addSourceContainer(jproject2, "src2");
076:
077: StandardJavaElementContentProvider provider = new StandardJavaElementContentProvider();
078: ILabelProvider labelProvider = new JavaElementLabelProvider(
079: JavaElementLabelProvider.SHOW_DEFAULT);
080: CheckedTreeSelectionDialog dialog = new CheckedTreeSelectionDialog(
081: getShell(), labelProvider, provider);
082: dialog.setComparator(new JavaElementComparator());
083: dialog.setTitle("Title"); //$NON-NLS-1$
084: dialog.setMessage("Select the elements"); //$NON-NLS-1$
085:
086: dialog.setInput(jproject.getJavaModel());
087: dialog.setInitialSelection(initSelection);
088: dialog.setExpandedElements(new Object[] { initSelection,
089: jproject });
090:
091: DialogCheck.assertDialog(dialog);
092:
093: System.out.println("Result:");
094: Object[] checkedElements = dialog.getResult();
095: for (int i = 0; i < checkedElements.length; i++) {
096: System.out.println(labelProvider
097: .getText(checkedElements[i]));
098: }
099:
100: JavaProjectHelper.delete(jproject);
101: JavaProjectHelper.delete(jproject2);
102: }
103:
104: public void testPackageSelectionDialog01() throws CoreException,
105: IOException, InvocationTargetException {
106: IJavaProject jproject = JavaProjectHelper
107: .createJavaProjectWithJUnitSource(PROJECT_NAME, "src",
108: "bin");
109:
110: SelectionDialog dialog = JavaUI.createPackageDialog(getShell(),
111: jproject,
112: IJavaElementSearchConstants.CONSIDER_BINARIES, "");
113: dialog.setBlockOnOpen(false);
114: dialog.open();
115:
116: DialogCheck.assertDialog(dialog);
117:
118: JavaProjectHelper.delete(jproject);
119: }
120:
121: public void testPackageSelectionDialog02() throws CoreException,
122: IOException, InvocationTargetException {
123: IJavaProject jproject = JavaProjectHelper
124: .createJavaProjectWithJUnitSource(PROJECT_NAME, "src",
125: "bin");
126:
127: IPackageFragmentRoot root = jproject.getPackageFragmentRoots()[0];
128: SelectionDialog dialog = JavaUI.createPackageDialog(getShell(),
129: root, "");
130: dialog.setBlockOnOpen(false);
131: dialog.open();
132:
133: DialogCheck.assertDialog(dialog);
134:
135: JavaProjectHelper.delete(jproject);
136: }
137:
138: }
|