Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 201886
Collapse All | Expand All

(-)src/org/eclipse/hyades/ui/internal/util/UIUtil.java (-9 / +34 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 12-23 Link Here
12
package org.eclipse.hyades.ui.internal.util;
12
package org.eclipse.hyades.ui.internal.util;
13
13
14
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.hyades.ui.HyadesUIPlugin;
15
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.resources.ResourcesPlugin;
16
import org.eclipse.jface.viewers.SelectionChangedEvent;
17
import org.eclipse.jface.viewers.SelectionChangedEvent;
17
import org.eclipse.jface.viewers.StructuredViewer;
18
import org.eclipse.jface.viewers.StructuredViewer;
18
import org.eclipse.jface.viewers.ViewerFilter;
19
import org.eclipse.jface.viewers.ViewerFilter;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.events.VerifyEvent;
21
import org.eclipse.swt.events.VerifyEvent;
22
import org.eclipse.tptp.platform.common.internal.CommonPlugin;
21
import org.eclipse.ui.IEditorPart;
23
import org.eclipse.ui.IEditorPart;
22
import org.eclipse.ui.IEditorReference;
24
import org.eclipse.ui.IEditorReference;
23
import org.eclipse.ui.IFileEditorInput;
25
import org.eclipse.ui.IFileEditorInput;
Lines 25-34 Link Here
25
27
26
/**
28
/**
27
 * Contains UI utility methods.
29
 * Contains UI utility methods.
30
 * <p/>
28
 * 
31
 * 
29
 * @author marcelop
32
 * 
30
 * @author popescu
33
 * @author  Marcelo Paternostro
31
 * @since 0.0.1
34
 * @author  Valentina Popescu
35
 * @author  Paul E. Slauenwhite
36
 * @version April 16, 2008
37
 * @since   January 26, 2005
32
 */
38
 */
33
public class UIUtil extends org.eclipse.tptp.platform.common.ui.internal.util.UIUtil 
39
public class UIUtil extends org.eclipse.tptp.platform.common.ui.internal.util.UIUtil 
34
{	
40
{	
Lines 47-53 Link Here
47
		}
53
		}
48
		catch(RuntimeException e)
54
		catch(RuntimeException e)
49
		{
55
		{
50
			HyadesUIPlugin.logError(e);
56
			CommonPlugin.logError(e);
51
			return false;
57
			return false;
52
		}
58
		}
53
		
59
		
Lines 235-241 Link Here
235
		return null;
241
		return null;
236
	}
242
	}
237
	
243
	
238
244
    /**
239
	
245
     * Resolves the first open {@link IProject} in the workspace.
240
246
     * <p/>
247
     * In no projects exist in the workspace or all projects in
248
     * the workspace are closed, <code>null</code> is returned.
249
     * <p/>
250
     * 
251
     * @return The first open {@link IProject} in the workspace, otherwise <code>null</code>.
252
     */
253
    public static IProject getFirstOpenProject(){
254
    	
255
    	IProject[] workspaceProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
256
    	
257
    	for (int counter = 0; counter < workspaceProjects.length; counter++) {
258
			
259
    		if(workspaceProjects[counter].isOpen()){
260
    			return (workspaceProjects[counter]);
261
    		}
262
		}
263
    	
264
    	return null;
265
    }
241
}
266
}
(-)src/org/eclipse/hyades/ui/internal/wizard/HyadesNewWizard.java (-18 / +68 lines)
Lines 12-17 Link Here
12
package org.eclipse.hyades.ui.internal.wizard;
12
package org.eclipse.hyades.ui.internal.wizard;
13
13
14
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.IWorkspaceRoot;
17
import org.eclipse.core.resources.IWorkspaceRoot;
17
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.resources.ResourcesPlugin;
Lines 20-41 Link Here
20
import org.eclipse.hyades.ui.HyadesUIPlugin;
21
import org.eclipse.hyades.ui.HyadesUIPlugin;
21
import org.eclipse.hyades.ui.internal.util.ResourceUtil;
22
import org.eclipse.hyades.ui.internal.util.ResourceUtil;
22
import org.eclipse.hyades.ui.internal.util.UIUtil;
23
import org.eclipse.hyades.ui.internal.util.UIUtil;
24
import org.eclipse.jdt.core.IJavaProject;
23
import org.eclipse.jface.viewers.IStructuredSelection;
25
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.jface.viewers.StructuredSelection;
26
import org.eclipse.jface.viewers.StructuredSelection;
25
import org.eclipse.tptp.platform.common.ui.wizard.LocationPage;
27
import org.eclipse.tptp.platform.common.ui.wizard.LocationPage;
26
import org.eclipse.ui.INewWizard;
28
import org.eclipse.ui.INewWizard;
27
import org.eclipse.ui.PartInitException;
29
import org.eclipse.ui.PartInitException;
30
import org.eclipse.ui.actions.NewProjectAction;
28
31
29
/**
32
/**
30
 * Abstract extension of the Eclipse's <code>NewWizard</code> that defines a location 
33
 * Abstract extension of the Eclipse's <code>NewWizard</code> that defines a location 
31
 * page and a "name and description" page.  The subclasses are supposed to add the pages
34
 * page and a "name and description" page.  The subclasses are supposed to add the pages
32
 * in the appropriate order and using the correct values for their titles and descriptions.
35
 * in the appropriate order and using the correct values for their titles and descriptions.
33
 * 
36
 * <p/>
34
 * <p>This implementation is based on the 
37
 * This implementation is based on the 
35
 * <code>org.eclipse.ui.wizards.newresource.BasicNewResourceWizard</code> class.
38
 * <code>org.eclipse.ui.wizards.newresource.BasicNewResourceWizard</code> class.
39
 * <p/>
40
 * 
36
 * 
41
 * 
37
 * @author marcelop
42
 * @author  Marcelo Paternostro
38
 * @since 0.0.1
43
 * @author  Paul E. Slauenwhite
44
 * @version April 16, 2008
45
 * @since   January 26, 2005
39
 */
46
 */
40
public abstract class HyadesNewWizard extends HyadesWizard implements INewWizard {
47
public abstract class HyadesNewWizard extends HyadesWizard implements INewWizard {
41
    /*
48
    /*
Lines 63-86 Link Here
63
    }
70
    }
64
71
65
    /**
72
    /**
66
     * Adjusts the selection passed to this wizard.
73
     * Adjusts the {@link IStructuredSelection} passed to this wizard.
67
     * @return IStructuredSelection
74
     * <p/>
75
     * 
76
     * @return The adjusted {@link IStructuredSelection}.
68
     */
77
     */
69
    protected IStructuredSelection adjustSeletion() {
78
    protected IStructuredSelection adjustSeletion() {
70
        IStructuredSelection structuredSelection = getSelection();
79
        
71
        if (getDialogSettings() != null) {
80
		//Case 1: Workspace does not contain an open project so open the create project wizard (File >> New >> Project...): 
72
            if ((structuredSelection == null) || (structuredSelection.isEmpty())) {
81
    	if(UIUtil.getFirstOpenProject() == null){
73
                String lastSelection = getDialogSettings().get(SET_LAST_SELECTION);
82
        	
74
                if (lastSelection != null) {
83
    		new NewProjectAction().run();
75
                    IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(lastSelection);
84
    		
76
                    if ((resource != null) && (resource.exists())) structuredSelection = new StructuredSelection(resource);
85
    		IProject newProject = UIUtil.getFirstOpenProject();
77
                }
86
    		
78
            }
87
    		if(newProject != null){
79
        }
88
    			return (new StructuredSelection(newProject));    			
89
    		}    		
90
    	}
91
92
    	IStructuredSelection structuredSelection = getSelection();
93
94
		//Case 2: Selection contains a resource (project or folder/file) so check if accessible (open for projects and exists for folders/files): 
95
    	if ((structuredSelection != null) && (!structuredSelection.isEmpty())) {
96
97
    		IResource resource = null;
98
    		Object firstSelectedElement = structuredSelection.getFirstElement();
99
			        	
100
    		if(firstSelectedElement instanceof IResource){    			
101
    			resource = ((IResource)(firstSelectedElement));        		
102
    		}
103
    		else if(firstSelectedElement instanceof IJavaProject){
104
    			resource = ((IJavaProject)(firstSelectedElement)).getProject();
105
    		}    		
106
107
    		if ((resource != null) && (resource.isAccessible())){
108
    	    	return structuredSelection;
109
    	    }
110
    	}
111
112
		//Case 3: Selection is null/empty so check if the last selected resource (project or folder/file) for the dialog is accessible (open for projects and exists for folders/files): 
113
    	if (getDialogSettings() != null) {
114
115
    		String lastSelection = getDialogSettings().get(SET_LAST_SELECTION);
116
117
    		if (lastSelection != null) {            
118
    			
119
    			IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(lastSelection);          
120
121
    			if ((resource != null) && (resource.isAccessible())){
122
    	    		return (new StructuredSelection(resource));
123
    	    	}
124
    		}
125
    	}
80
126
81
        return structuredSelection;
127
    	//Case 4: Return an empty selection:
128
    	return (StructuredSelection.EMPTY);
82
    }
129
    }
83
130
    
84
    /**
131
    /**
85
     * Returns the location page used by this wizard.
132
     * Returns the location page used by this wizard.
86
     * @return LocationPage
133
     * @return LocationPage
Lines 138-143 Link Here
138
            handleException(file.getFullPath().toString(), e);
185
            handleException(file.getFullPath().toString(), e);
139
        }
186
        }
140
187
188
        //Save the last selected resource (project or folder/file) for the dialog:
189
        getDialogSettings().put(SET_LAST_SELECTION, getLocationPage().getContainerFullPath().toString());
190
        
141
        return true;
191
        return true;
142
    }
192
    }
143
193
(-)src-ui/org/eclipse/tptp/test/tools/junit/plugin/internal/ui/resources/messages.properties (+1 lines)
Lines 62-67 Link Here
62
WORKBENCH_DETAILS_WIZPAGE_MISSING_ECLIPSE_DIRECTORY=Eclipse location is missing.
62
WORKBENCH_DETAILS_WIZPAGE_MISSING_ECLIPSE_DIRECTORY=Eclipse location is missing.
63
WORKBENCH_DETAILS_WIZPAGE_MISSING_WORKSPACE_DIRECTORY=Workspace location is missing.   
63
WORKBENCH_DETAILS_WIZPAGE_MISSING_WORKSPACE_DIRECTORY=Workspace location is missing.   
64
PLUGIN_TEST_NEW_WIZARD_TITLE=New JUnit Plug-in Test
64
PLUGIN_TEST_NEW_WIZARD_TITLE=New JUnit Plug-in Test
65
PLUGIN_TEST_NEW_WIZARD_PLUGIN_PROJECT_ERROR=The selected source folder does not belong to a plug-in project.
65
#Translators: please keep the <A>...</A> delimiters in the string below!
66
#Translators: please keep the <A>...</A> delimiters in the string below!
66
WORKBENCH_DETAILS_WIZPAGE_TARGET_PLATFORM_LINK=The settings defined in the <A>target platform</A> will be used.
67
WORKBENCH_DETAILS_WIZPAGE_TARGET_PLATFORM_LINK=The settings defined in the <A>target platform</A> will be used.
67
68
(-)src-ui/org/eclipse/tptp/test/tools/junit/plugin/internal/ui/resources/PluginMessages.java (-2 / +4 lines)
Lines 17-23 Link Here
17
 * Plugin messages.
17
 * Plugin messages.
18
 * 
18
 * 
19
 * @author  Paul E. Slauenwhite
19
 * @author  Paul E. Slauenwhite
20
 * @version January 17, 2007
20
 * @version April 16, 2007
21
 * @since   April 20, 2007
21
 * @since   April 20, 2007
22
 */
22
 */
23
public class PluginMessages extends NLS {
23
public class PluginMessages extends NLS {
Lines 102-108 Link Here
102
102
103
	public static String WORKBENCH_DETAILS_WIZPAGE_ECLIPSE_DIRECTORY;
103
	public static String WORKBENCH_DETAILS_WIZPAGE_ECLIPSE_DIRECTORY;
104
	
104
	
105
	public static String  WORKBENCH_DETAILS_WIZPAGE_WORKSPACE_DIRECTORY;
105
	public static String WORKBENCH_DETAILS_WIZPAGE_WORKSPACE_DIRECTORY;
106
	
106
	
107
	public static String WORKBENCH_DETAILS_WIZPAGE_OPERATING_SYSTEM;
107
	public static String WORKBENCH_DETAILS_WIZPAGE_OPERATING_SYSTEM;
108
108
Lines 124-128 Link Here
124
124
125
	public static String WORKBENCH_DETAILS_WIZPAGE_UI_THREAD;
125
	public static String WORKBENCH_DETAILS_WIZPAGE_UI_THREAD;
126
	
126
	
127
	public static String PLUGIN_TEST_NEW_WIZARD_PLUGIN_PROJECT_ERROR;
128
	
127
	public static String PluginJUnitImportWizard_title;
129
	public static String PluginJUnitImportWizard_title;
128
}
130
}
(-)src-ui/org/eclipse/tptp/test/tools/junit/plugin/internal/ui/wizard/PluginSourcePage.java (-6 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 18-33 Link Here
18
import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin;
18
import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin;
19
import org.eclipse.hyades.test.tools.ui.java.internal.junit.wizard.SourcePage;
19
import org.eclipse.hyades.test.tools.ui.java.internal.junit.wizard.SourcePage;
20
import org.eclipse.jdt.core.IPackageFragmentRoot;
20
import org.eclipse.jdt.core.IPackageFragmentRoot;
21
import org.eclipse.tptp.test.tools.junit.plugin.internal.ui.resources.PluginMessages;
21
22
22
/**
23
/**
23
 * Page that allows to specify the details about the generated source code
24
 * Page that allows to specify the details about the generated source code
24
 * for a JUnit plugin test suite.
25
 * for a JUnit plug-in test suite.
25
 * This implementation is reusing the source page for regular JUnit test suites,
26
 * This implementation is reusing the source page for regular JUnit test suites,
26
 * with the only difference that it adds restrictions on the selected source folder
27
 * with the only difference that it adds restrictions on the selected source folder
27
 * (the source folder must belong to a plugin project, and this plugin should have
28
 * (the source folder must belong to a plug-in project, and this plug-in should have
28
 * specific dependencies).
29
 * specific dependencies).
29
 * @author jcanches
30
 * <p/>
30
 * @since 4.1
31
 * 
32
 * 
33
 * @author  Julien Canches
34
 * @author  Paul E. Slauenwhite
35
 * @version April 16, 2008
36
 * @since   April 20, 2007
31
 */
37
 */
32
public class PluginSourcePage extends SourcePage {
38
public class PluginSourcePage extends SourcePage {
33
39
Lines 37-43 Link Here
37
		
43
		
38
		IProject project = root.getJavaProject().getProject();
44
		IProject project = root.getJavaProject().getProject();
39
		if (!PluginProjectUtil.isStrictPluginProject(project)) {
45
		if (!PluginProjectUtil.isStrictPluginProject(project)) {
40
			return new Status(IStatus.ERROR, ToolsUiPlugin.getID(), 1, "The selected source folder does not belong to a plugin project", null); //$NON-NLS-1$
46
			return new Status(IStatus.ERROR, ToolsUiPlugin.getID(), 1, PluginMessages.PLUGIN_TEST_NEW_WIZARD_PLUGIN_PROJECT_ERROR, null);
41
		}
47
		}
42
		
48
		
43
		return super.validateProjectClasspath();
49
		return super.validateProjectClasspath();

Return to bug 201886