View | Details | Raw Unified | Return to bug 248103 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/internal/views/properties/messages.properties (+3 lines)
Lines 29-34 Link Here
29
Filter_text = Show &Advanced Properties
29
Filter_text = Show &Advanced Properties
30
Filter_toolTip = Show Advanced Properties
30
Filter_toolTip = Show Advanced Properties
31
31
32
Pin_text = &Pin to selection
33
Pin_toolTip = Pin property to current selection
34
32
PropertyViewer_property = Property
35
PropertyViewer_property = Property
33
PropertyViewer_value = Value
36
PropertyViewer_value = Value
34
PropertyViewer_misc = Misc
37
PropertyViewer_misc = Misc
(-)src/org/eclipse/ui/internal/views/properties/PropertiesMessages.java (+6 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 * IBM - Initial API and implementation
9
 * IBM - Initial API and implementation
10
 * Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal.views.properties;
12
package org.eclipse.ui.internal.views.properties;
12
13
Lines 47-52 Link Here
47
	public static String Filter_toolTip;
48
	public static String Filter_toolTip;
48
49
49
	/** */
50
	/** */
51
	public static String Pin_text;
52
	/** */
53
	public static String Pin_toolTip;
54
55
	/** */
50
	public static String PropertyViewer_property;
56
	public static String PropertyViewer_property;
51
	/** */
57
	/** */
52
	public static String PropertyViewer_value;
58
	public static String PropertyViewer_value;
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 2-8 Link Here
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.ui.views; singleton:=true
4
Bundle-SymbolicName: org.eclipse.ui.views; singleton:=true
5
Bundle-Version: 3.3.100.qualifier
5
Bundle-Version: 3.4.0.qualifier
6
Bundle-ClassPath: .
6
Bundle-ClassPath: .
7
Bundle-Activator: org.eclipse.ui.internal.views.ViewsPlugin
7
Bundle-Activator: org.eclipse.ui.internal.views.ViewsPlugin
8
Bundle-ActivationPolicy: lazy
8
Bundle-ActivationPolicy: lazy
(-)src/org/eclipse/ui/views/properties/IPropertiesHelpContextIds.java (+4 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.views.properties;
12
package org.eclipse.ui.views.properties;
12
13
Lines 36-41 Link Here
36
    public static final String COPY_PROPERTY_ACTION = PREFIX
37
    public static final String COPY_PROPERTY_ACTION = PREFIX
37
            + "properties_copy_action_context"; //$NON-NLS-1$
38
            + "properties_copy_action_context"; //$NON-NLS-1$
38
39
40
    public static final String PIN_ACTION = PREFIX
41
    		+ "properties_pin_action_context"; //$NON-NLS-1$;
42
    
39
    // Views
43
    // Views
40
    public static final String PROPERTY_SHEET_VIEW = PREFIX
44
    public static final String PROPERTY_SHEET_VIEW = PREFIX
41
            + "property_sheet_view_context"; //$NON-NLS-1$
45
            + "property_sheet_view_context"; //$NON-NLS-1$
(-)src/org/eclipse/ui/views/properties/PropertySheet.java (-11 / +131 lines)
Lines 7-20 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.views.properties;
12
package org.eclipse.ui.views.properties;
12
13
14
import org.eclipse.jface.action.IAction;
15
import org.eclipse.jface.action.IMenuManager;
16
import org.eclipse.jface.action.IToolBarManager;
17
import org.eclipse.jface.action.Separator;
13
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.viewers.ISelection;
14
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.ui.IMemento;
15
import org.eclipse.ui.ISaveablePart;
21
import org.eclipse.ui.ISaveablePart;
16
import org.eclipse.ui.ISelectionListener;
22
import org.eclipse.ui.ISelectionListener;
17
import org.eclipse.ui.IViewSite;
23
import org.eclipse.ui.IViewSite;
24
import org.eclipse.ui.IWorkbenchActionConstants;
18
import org.eclipse.ui.IWorkbenchPage;
25
import org.eclipse.ui.IWorkbenchPage;
19
import org.eclipse.ui.IWorkbenchPart;
26
import org.eclipse.ui.IWorkbenchPart;
20
import org.eclipse.ui.PartInitException;
27
import org.eclipse.ui.PartInitException;
Lines 22-29 Link Here
22
import org.eclipse.ui.part.IContributedContentsView;
29
import org.eclipse.ui.part.IContributedContentsView;
23
import org.eclipse.ui.part.IPage;
30
import org.eclipse.ui.part.IPage;
24
import org.eclipse.ui.part.IPageBookViewPage;
31
import org.eclipse.ui.part.IPageBookViewPage;
32
import org.eclipse.ui.part.IShowInSource;
33
import org.eclipse.ui.part.IShowInTarget;
25
import org.eclipse.ui.part.PageBook;
34
import org.eclipse.ui.part.PageBook;
26
import org.eclipse.ui.part.PageBookView;
35
import org.eclipse.ui.part.PageBookView;
36
import org.eclipse.ui.part.ShowInContext;
27
37
28
/**
38
/**
29
 * Main class for the Property Sheet View.
39
 * Main class for the Property Sheet View.
Lines 61-67 Link Here
61
 * @noinstantiate This class is not intended to be instantiated by clients.
71
 * @noinstantiate This class is not intended to be instantiated by clients.
62
 * @noextend This class is not intended to be subclassed by clients.
72
 * @noextend This class is not intended to be subclassed by clients.
63
 */
73
 */
64
public class PropertySheet extends PageBookView implements ISelectionListener {
74
public class PropertySheet extends PageBookView implements ISelectionListener, IShowInTarget, IShowInSource {
65
    /**
75
    /**
66
     * No longer used but preserved to avoid api change
76
     * No longer used but preserved to avoid api change
67
     */
77
     */
Lines 73-78 Link Here
73
    private ISelection bootstrapSelection;
83
    private ISelection bootstrapSelection;
74
84
75
    /**
85
    /**
86
     * The current selection of the property sheet
87
     */
88
    private ISelection currentSelection;
89
90
    /**
91
     * The current part for which this property sheets is active
92
     */
93
	private IWorkbenchPart currentPart;
94
95
	/**
96
	 * Whether this property sheet instance is pinned or not 
97
	 */
98
	private IAction pinPropertySheetAction;
99
	
100
    /**
76
     * Creates a property sheet view.
101
     * Creates a property sheet view.
77
     */
102
     */
78
    public PropertySheet() {
103
    public PropertySheet() {
Lines 84-101 Link Here
84
     * Returns the default property sheet page.
109
     * Returns the default property sheet page.
85
     */
110
     */
86
    protected IPage createDefaultPage(PageBook book) {
111
    protected IPage createDefaultPage(PageBook book) {
87
        PropertySheetPage page = new PropertySheetPage();
112
        IPageBookViewPage page = (IPageBookViewPage) ViewsPlugin.getAdapter(this,
113
                IPropertySheetPage.class, false);
114
        if(page == null) {
115
        	page = new PropertySheetPage();
116
        }
88
        initPage(page);
117
        initPage(page);
89
        page.createControl(book);
118
        page.createControl(book);
90
        return page;
119
        return page;
91
    }
120
    }
92
121
93
    /**
122
	/**
94
     * The <code>PropertySheet</code> implementation of this <code>IWorkbenchPart</code>
123
     * The <code>PropertySheet</code> implementation of this <code>IWorkbenchPart</code>
95
     * method creates a <code>PageBook</code> control with its default page showing.
124
     * method creates a <code>PageBook</code> control with its default page showing.
96
     */
125
     */
97
    public void createPartControl(Composite parent) {
126
    public void createPartControl(Composite parent) {
98
        super.createPartControl(parent);
127
        super.createPartControl(parent);
128
         
129
        pinPropertySheetAction = new PinPropertySheetAction();
130
		IMenuManager menuManager = getViewSite().getActionBars()
131
				.getMenuManager();
132
		menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
133
		menuManager.add(pinPropertySheetAction);
134
135
		IToolBarManager toolBarManager = getViewSite().getActionBars()
136
				.getToolBarManager();
137
		menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
138
		toolBarManager.add(pinPropertySheetAction);
139
		
99
        getSite().getPage().getWorkbenchWindow().getWorkbench().getHelpSystem()
140
        getSite().getPage().getWorkbenchWindow().getWorkbench().getHelpSystem()
100
				.setHelp(getPageBook(),
141
				.setHelp(getPageBook(),
101
						IPropertiesHelpContextIds.PROPERTY_SHEET_VIEW);
142
						IPropertiesHelpContextIds.PROPERTY_SHEET_VIEW);
Lines 116-122 Link Here
116
     * Method declared on PageBookView.
157
     * Method declared on PageBookView.
117
     */
158
     */
118
    protected PageRec doCreatePage(IWorkbenchPart part) {
159
    protected PageRec doCreatePage(IWorkbenchPart part) {
119
        // Try to get a custom property sheet page.
160
        // Get a custom property sheet page but not if the part is also a
161
		// PropertySheet. In this case the child property sheet would
162
		// accidentally reuse the parent's property sheet page.
163
    	if(part instanceof PropertySheet) {
164
    		return null;
165
    	}
120
        IPropertySheetPage page = (IPropertySheetPage) ViewsPlugin.getAdapter(part,
166
        IPropertySheetPage page = (IPropertySheetPage) ViewsPlugin.getAdapter(part,
121
                IPropertySheetPage.class, false);
167
                IPropertySheetPage.class, false);
122
        if (page != null) {
168
        if (page != null) {
Lines 158-176 Link Here
158
     * Method declared on IViewPart.
204
     * Method declared on IViewPart.
159
     */
205
     */
160
    public void init(IViewSite site) throws PartInitException {
206
    public void init(IViewSite site) throws PartInitException {
161
        site.getPage().addSelectionListener(this);
207
   		site.getPage().addSelectionListener(this);
162
        super.init(site);
208
   		super.init(site);
163
    }
209
    }
164
210
165
    /* (non-Javadoc)
211
    /* (non-Javadoc)
212
	 * @see org.eclipse.ui.part.ViewPart#saveState(org.eclipse.ui.IMemento)
213
	 * since 3.4
214
	 */
215
	public void saveState(IMemento memento) {
216
		// close all but the primary/parent property sheet
217
		String secondaryId = getViewSite().getSecondaryId();
218
		if (null == secondaryId) {
219
			super.saveState(memento);
220
		} else {
221
			getViewSite().getPage().hideView(this);
222
		}
223
	}
224
225
    /* (non-Javadoc)
166
     * Method declared on PageBookView.
226
     * Method declared on PageBookView.
167
     * The property sheet may show properties for any view other than this view.
227
     * The property sheet may show properties for any view other than this view.
168
     */
228
     */
169
    protected boolean isImportant(IWorkbenchPart part) {
229
    protected boolean isImportant(IWorkbenchPart part) {
170
        return part != this;
230
    	 return pinPropertySheetAction == null
231
    	 				|| (pinPropertySheetAction != null && !pinPropertySheetAction
232
    	 						.isChecked()) && !(part instanceof PropertySheet);
171
    }
233
    }
172
234
173
    /**
235
    /* (non-Javadoc)
236
	 * @see org.eclipse.ui.part.PageBookView#partClosed(org.eclipse.ui.IWorkbenchPart)
237
	 * since 3.4
238
	 */
239
	public void partClosed(IWorkbenchPart part) {
240
		if (pinPropertySheetAction.isChecked() && part.equals(currentPart)) {
241
			pinPropertySheetAction.setChecked(false);
242
		}
243
		super.partClosed(part);
244
	}
245
246
	/**
174
     * The <code>PropertySheet</code> implementation of this <code>IPartListener</code>
247
     * The <code>PropertySheet</code> implementation of this <code>IPartListener</code>
175
     * method first sees if the active part is an <code>IContributedContentsView</code>
248
     * method first sees if the active part is an <code>IContributedContentsView</code>
176
     * adapter and if so, asks it for its contributing part.
249
     * adapter and if so, asks it for its contributing part.
Lines 190-195 Link Here
190
			super.partActivated(part);
263
			super.partActivated(part);
191
		}
264
		}
192
265
266
        if(isImportant(part)) {
267
        	currentPart = part;
268
        }
269
        
193
        // When the view is first opened, pass the selection to the page		
270
        // When the view is first opened, pass the selection to the page		
194
        if (bootstrapSelection != null) {
271
        if (bootstrapSelection != null) {
195
            IPropertySheetPage page = (IPropertySheetPage) getCurrentPage();
272
            IPropertySheetPage page = (IPropertySheetPage) getCurrentPage();
Lines 206-219 Link Here
206
     */
283
     */
207
    public void selectionChanged(IWorkbenchPart part, ISelection sel) {
284
    public void selectionChanged(IWorkbenchPart part, ISelection sel) {
208
        // we ignore our own selection or null selection
285
        // we ignore our own selection or null selection
209
        if (part == this || sel == null) {
286
		if (sel == null || !isImportant(part)
287
				|| (!isImportant(part) && sel.equals(currentSelection))) {
210
			return;
288
			return;
211
		}
289
		}
212
290
        
291
        currentPart = part;
292
        currentSelection = sel;
293
        
213
        // pass the selection to the page		
294
        // pass the selection to the page		
214
        IPropertySheetPage page = (IPropertySheetPage) getCurrentPage();
295
        IPropertySheetPage page = (IPropertySheetPage) getCurrentPage();
215
        if (page != null) {
296
        if (page != null) {
216
			page.selectionChanged(part, sel);
297
			page.selectionChanged(currentPart, currentSelection);
217
		}
298
		}
218
    }
299
    }
219
    
300
    
Lines 246-249 Link Here
246
		}
327
		}
247
		return null;
328
		return null;
248
	}
329
	}
330
	
331
	/**
332
	 * @return whether this property sheet is currently pinned
333
	 * @since 3.4
334
	 */
335
	public boolean isPinned() {
336
		return pinPropertySheetAction.isChecked();
337
	}
338
339
	/* (non-Javadoc)
340
	 * @see org.eclipse.ui.part.IShowInSource#getShowInContext()
341
	 * @since 3.4
342
	 */
343
	public ShowInContext getShowInContext() {
344
		return new PropertyShowInContext(currentPart, currentSelection);
345
	}
346
	
347
	/* (non-Javadoc)
348
	 * @see org.eclipse.ui.part.IShowInTarget#show(org.eclipse.ui.part.ShowInContext)
349
	 * @since 3.4
350
	 */
351
	public boolean show(ShowInContext aContext) {
352
		if (!pinPropertySheetAction.isChecked()
353
				&& aContext instanceof PropertyShowInContext) {
354
			PropertyShowInContext context = (PropertyShowInContext) aContext;
355
			partActivated(context.getPart());
356
			selectionChanged(context.getPart(), context.getSelection());
357
			return true;
358
		}
359
		return false;
360
	}
361
362
	/***
363
	 * @param pinned Whether this sheet should be pinned
364
	 * @since 3.4
365
	 */
366
	public void setPinned(boolean pinned) {
367
		pinPropertySheetAction.setChecked(pinned);
368
	}
249
}
369
}
(-)plugin.properties (+1 lines)
Lines 12-16 Link Here
12
providerName= Eclipse.org
12
providerName= Eclipse.org
13
13
14
Views.PropertySheet = Properties
14
Views.PropertySheet = Properties
15
Views.NewPropertySheet = Open new properties
15
Views.ContentOutline = Outline
16
Views.ContentOutline = Outline
16
17
(-)plugin.xml (-3 / +33 lines)
Lines 5-15 Link Here
5
     <extension
5
     <extension
6
         point="org.eclipse.ui.views">
6
         point="org.eclipse.ui.views">
7
      <view
7
      <view
8
            name="%Views.PropertySheet"
8
            allowMultiple="true"
9
            icon="$nl$/icons/full/eview16/prop_ps.gif"
10
            category="org.eclipse.ui"
9
            category="org.eclipse.ui"
11
            class="org.eclipse.ui.views.properties.PropertySheet"
10
            class="org.eclipse.ui.views.properties.PropertySheet"
12
            id="org.eclipse.ui.views.PropertySheet">
11
            icon="$nl$/icons/full/eview16/prop_ps.gif"
12
            id="org.eclipse.ui.views.PropertySheet"
13
            name="%Views.PropertySheet">
13
      </view>
14
      </view>
14
      <view
15
      <view
15
            name="%Views.ContentOutline"
16
            name="%Views.ContentOutline"
Lines 19-23 Link Here
19
            id="org.eclipse.ui.views.ContentOutline">
20
            id="org.eclipse.ui.views.ContentOutline">
20
      </view>
21
      </view>
21
   </extension>
22
   </extension>
23
     <extension
24
           point="org.eclipse.ui.menus">
25
		<menuContribution
26
				locationURI="popup:org.eclipse.ui.menus.showInMenu">
27
			<command
28
				commandId="org.eclipse.ui.views.properties.NewPropertySheetCommand"
29
				icon="platform:/plugin/org.eclipse.ui.views/icons/full/eview16/prop_ps.gif"
30
				label="%Views.PropertySheet"
31
				style="push">
32
	        </command>
33
		</menuContribution>
34
  <menuContribution
35
        locationURI="toolbar:org.eclipse.ui.views.PropertySheet">
36
     <command
37
           commandId="org.eclipse.ui.views.properties.NewPropertySheetCommand"
38
           icon="icons/full/elcl16/new.gif"
39
           label="%Views.NewPropertySheet"
40
           style="push">
41
     </command>
42
  </menuContribution>
43
	</extension>
44
     <extension
45
           point="org.eclipse.ui.commands">
46
        <command
47
              defaultHandler="org.eclipse.ui.views.properties.NewPropertySheetHandler"
48
              id="org.eclipse.ui.views.properties.NewPropertySheetCommand"
49
              name="%Views.PropertySheet">
50
        </command>
51
     </extension>
22
   
52
   
23
</plugin>
53
</plugin>
(-)src/org/eclipse/ui/views/properties/NewPropertySheetHandler.java (+128 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 ******************************************************************************/
11
12
package org.eclipse.ui.views.properties;
13
14
import org.eclipse.core.commands.AbstractHandler;
15
import org.eclipse.core.commands.ExecutionEvent;
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.ui.IPageLayout;
19
import org.eclipse.ui.IViewReference;
20
import org.eclipse.ui.IWorkbenchPage;
21
import org.eclipse.ui.IWorkbenchPart;
22
import org.eclipse.ui.PartInitException;
23
import org.eclipse.ui.handlers.HandlerUtil;
24
import org.eclipse.ui.part.IShowInSource;
25
import org.eclipse.ui.part.ShowInContext;
26
27
/**
28
 * @since 3.4
29
 */
30
public class NewPropertySheetHandler extends AbstractHandler {
31
32
	/**
33
	 * Command id
34
	 */
35
	public static final String ID = "org.eclipse.ui.views.properties.NewPropertySheetCommand"; //$NON-NLS-1$
36
37
	/**
38
	 * First tries to find a suitable instance to reuse for the given context,
39
	 * then creates a new instance if necessary.
40
	 * 
41
	 * @param event
42
	 * @return an instance for the given context
43
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
44
	 */
45
	public Object execute(ExecutionEvent event) throws ExecutionException {
46
		IWorkbenchPart activePart = HandlerUtil.getActivePartChecked(event);
47
48
		PropertyShowInContext context = getShowInContext(event);
49
		try {
50
			PropertySheet sheet = findPropertySheet(event, context);
51
			sheet.show(context);
52
			if (activePart instanceof PropertySheet) {
53
				PropertySheet parent = (PropertySheet) activePart;
54
				parent.setPinned(true);
55
			} else {
56
				sheet.setPinned(true);
57
			}
58
		} catch (PartInitException e) {
59
			throw new ExecutionException("Part could not be initialized", e); //$NON-NLS-1$
60
		}
61
		return null;
62
	}
63
64
	/**
65
	 * @param event
66
	 *            {@link ExecutionEvent} for which the
67
	 *            {@link PropertyShowInContext} is requested
68
	 * @return a {@link PropertyShowInContext} containing the the
69
	 *         {@link ISelection} and {@link IWorkbenchPart} for the given
70
	 *         {@link ExecutionEvent}
71
	 * @throws ExecutionException
72
	 */
73
	protected PropertyShowInContext getShowInContext(ExecutionEvent event)
74
			throws ExecutionException {
75
		IWorkbenchPart activePart = HandlerUtil.getActivePartChecked(event);
76
		if (activePart instanceof PropertySheet) {
77
			PropertySheet sheet = (PropertySheet) activePart;
78
			return (PropertyShowInContext) sheet.getShowInContext();
79
		}
80
		IShowInSource adapter = (IShowInSource) activePart
81
				.getAdapter(IShowInSource.class);
82
		if (adapter != null) {
83
			ShowInContext showInContext = adapter.getShowInContext();
84
			return new PropertyShowInContext(activePart, showInContext);
85
		}
86
		return new PropertyShowInContext(activePart, HandlerUtil
87
				.getShowInSelection(event));
88
	}
89
90
	/**
91
	 * Returns a PropertySheet instance
92
	 * 
93
	 * @param event
94
	 * @param context
95
	 *            a {@link ShowInContext} to handle
96
	 * @return a PropertySheet that can handle the given {@link ShowInContext}
97
	 * @throws PartInitException
98
	 * @throws ExecutionException
99
	 */
100
	protected PropertySheet findPropertySheet(ExecutionEvent event,
101
			PropertyShowInContext context) throws PartInitException,
102
			ExecutionException {
103
		IWorkbenchPage page = HandlerUtil.getActivePartChecked(event).getSite()
104
				.getPage();
105
		String secondaryId = null;
106
		if (HandlerUtil.getActivePart(event) instanceof PropertySheet) {
107
			secondaryId = Long.toString(System.currentTimeMillis());
108
		} else {
109
			IViewReference[] refs = page.getViewReferences();
110
			for (int i = 0; i < refs.length; i++) {
111
				IViewReference viewReference = refs[i];
112
				if (IPageLayout.ID_PROP_SHEET.equals(viewReference.getId())) {
113
					secondaryId = Long.toString(System.currentTimeMillis());
114
					PropertySheet sheet = (PropertySheet) viewReference
115
							.getView(true);
116
					if (!sheet.isPinned()
117
							|| (sheet.isPinned() && sheet.getShowInContext()
118
									.equals(context))) {
119
						secondaryId = sheet.getViewSite().getSecondaryId();
120
						break;
121
					}
122
				}
123
			}
124
		}
125
		return (PropertySheet) page.showView(IPageLayout.ID_PROP_SHEET,
126
				secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
127
	}
128
}
(-)src/org/eclipse/ui/views/properties/PropertyShowInContext.java (+107 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 ******************************************************************************/
11
12
package org.eclipse.ui.views.properties;
13
14
import org.eclipse.jface.viewers.ISelection;
15
import org.eclipse.ui.IWorkbenchPart;
16
import org.eclipse.ui.part.ShowInContext;
17
18
/**
19
 * @since 3.4
20
 * 
21
 */
22
public class PropertyShowInContext extends ShowInContext {
23
24
	private IWorkbenchPart part;
25
26
	/**
27
	 * @param aPart
28
	 * @param selection
29
	 */
30
	public PropertyShowInContext(IWorkbenchPart aPart, ISelection selection) {
31
		super(selection, selection);
32
		part = aPart;
33
	}
34
35
	/**
36
	 * @param aPart
37
	 * @param aShowInContext
38
	 */
39
	public PropertyShowInContext(IWorkbenchPart aPart,
40
			ShowInContext aShowInContext) {
41
		super(aShowInContext.getInput(), aShowInContext.getSelection());
42
		part = aPart;
43
	}
44
45
	/**
46
	 * @return Returns the part.
47
	 */
48
	public IWorkbenchPart getPart() {
49
		return part;
50
	}
51
52
	/**
53
	 * @param part
54
	 *            The part to set.
55
	 */
56
	public void setPart(IWorkbenchPart part) {
57
		this.part = part;
58
	}
59
60
	/*
61
	 * (non-Javadoc)
62
	 * 
63
	 * @see java.lang.Object#hashCode()
64
	 */
65
	public int hashCode() {
66
		final int prime = 31;
67
		int result = 1;
68
		result = prime * result + ((part == null) ? 0 : part.hashCode())
69
				+ ((getSelection() == null) ? 0 : getSelection().hashCode())
70
				+ ((getInput() == null) ? 0 : getInput().hashCode());
71
		return result;
72
	}
73
74
	/*
75
	 * (non-Javadoc)
76
	 * 
77
	 * @see java.lang.Object#equals(java.lang.Object)
78
	 */
79
	public boolean equals(Object obj) {
80
		if (this == obj)
81
			return true;
82
		if (obj == null)
83
			return false;
84
		if (getClass() != obj.getClass())
85
			return false;
86
		PropertyShowInContext other = (PropertyShowInContext) obj;
87
		// part needs to be equal
88
		if (part == null) {
89
			if (other.part != null)
90
				return false;
91
		} else if (!part.equals(other.part))
92
			return false;
93
		// selection needs to be equal
94
		if (getSelection() == null) {
95
			if (other.getSelection() != null)
96
				return false;
97
		} else if (!getSelection().equals(other.getSelection()))
98
			return false;
99
		// input needs to be equal
100
		if (getInput() == null) {
101
			if (other.getInput() != null)
102
				return false;
103
		} else if (!getInput().equals(other.getInput()))
104
			return false;
105
		return true;
106
	}
107
}
(-)src/org/eclipse/ui/views/properties/PinPropertySheetAction.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 ******************************************************************************/
11
12
package org.eclipse.ui.views.properties;
13
14
import org.eclipse.jface.action.Action;
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.ui.PlatformUI;
17
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
18
import org.eclipse.ui.internal.WorkbenchImages;
19
import org.eclipse.ui.internal.views.properties.PropertiesMessages;
20
21
/**
22
 * Pins the properties view instance to the current selection.
23
 * 
24
 * @since 3.4
25
 */
26
public class PinPropertySheetAction extends Action {
27
28
	public PinPropertySheetAction() {
29
		super(PropertiesMessages.Pin_text, IAction.AS_CHECK_BOX);
30
31
		setId(PinPropertySheetAction.class.getName()
32
				+ "#" + Long.toString(System.currentTimeMillis())); //$NON-NLS-1$
33
		setToolTipText(PropertiesMessages.Pin_toolTip);
34
		setImageDescriptor(WorkbenchImages
35
				.getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_PIN_EDITOR));
36
		setDisabledImageDescriptor(WorkbenchImages
37
				.getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_PIN_EDITOR_DISABLED));
38
39
		PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
40
				IPropertiesHelpContextIds.PIN_ACTION);
41
	}
42
}
(-)plugin.xml (+5 lines)
Lines 3918-3923 Link Here
3918
            id="org.eclipse.ui.tests.enabledCount"
3918
            id="org.eclipse.ui.tests.enabledCount"
3919
            name="Enabled Count">
3919
            name="Enabled Count">
3920
      </command>
3920
      </command>
3921
      <command
3922
            defaultHandler="org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler"
3923
            id="org.eclipse.ui.views.properties.NewPropertySheetCommandTest"
3924
            name="TestNewPropertySheetCommand">
3925
      </command>
3921
   </extension>
3926
   </extension>
3922
   <extension
3927
   <extension
3923
         point="org.eclipse.ui.handlers">
3928
         point="org.eclipse.ui.handlers">
(-)Eclipse UI Tests/org/eclipse/ui/tests/session/SessionTests.java (-1 / +4 lines)
Lines 112-118 Link Here
112
				Bug108033Test.class));
112
				Bug108033Test.class));
113
		addTest(new WorkbenchSessionTest("editorSessionTests",
113
		addTest(new WorkbenchSessionTest("editorSessionTests",
114
				ArbitraryPropertiesViewTest.class));
114
				ArbitraryPropertiesViewTest.class));
115
		addTest(new WorkbenchSessionTest("editorSessionTests", NonRestorableViewTest.class));
115
		addTest(new WorkbenchSessionTest("editorSessionTests",
116
				NonRestorableViewTest.class));
117
		addTest(new WorkbenchSessionTest("editorSessionTests",
118
				NonRestorablePropertySheetTest.class));
116
		addTest(new WorkbenchSessionTest("editorSessionTests",
119
		addTest(new WorkbenchSessionTest("editorSessionTests",
117
				MarkersViewColumnSizeTest.class));
120
				MarkersViewColumnSizeTest.class));
118
	}
121
	}
(-)Eclipse JFace Tests/org/eclipse/ui/tests/session/NonRestorableView.java (-12 / +4 lines)
Lines 14-32 Link Here
14
import org.eclipse.ui.part.ViewPart;
14
import org.eclipse.ui.part.ViewPart;
15
15
16
public class NonRestorableView extends ViewPart {
16
public class NonRestorableView extends ViewPart {
17
	public static final String ID ="org.eclipse.ui.tests.session.NonRestorableView";
17
18
18
	public NonRestorableView() {
19
	public NonRestorableView() {	}
19
		// TODO Auto-generated constructor stub
20
	}
21
20
22
	public void createPartControl(Composite parent) {
21
	public void createPartControl(Composite parent) {}
23
		// TODO Auto-generated method stub
24
25
	}
26
27
	public void setFocus() {
28
		// TODO Auto-generated method stub
29
30
	}
31
22
23
	public void setFocus() {	}
32
}
24
}
(-)META-INF/MANIFEST.MF (-2 / +3 lines)
Lines 2-8 Link Here
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: Eclipse UI Tests
3
Bundle-Name: Eclipse UI Tests
4
Bundle-SymbolicName: org.eclipse.ui.tests; singleton:=true
4
Bundle-SymbolicName: org.eclipse.ui.tests; singleton:=true
5
Bundle-Version: 3.3.0.qualifier
5
Bundle-Version: 3.4.0.qualifier
6
Bundle-ClassPath: uitests.jar
6
Bundle-ClassPath: uitests.jar
7
Bundle-Activator: org.eclipse.core.internal.compatibility.PluginActivator
7
Bundle-Activator: org.eclipse.core.internal.compatibility.PluginActivator
8
Bundle-Vendor: Eclipse.org
8
Bundle-Vendor: Eclipse.org
Lines 25-31 Link Here
25
 org.eclipse.core.databinding,
25
 org.eclipse.core.databinding,
26
 org.eclipse.core.databinding.beans,
26
 org.eclipse.core.databinding.beans,
27
 org.eclipse.jface.databinding,
27
 org.eclipse.jface.databinding,
28
 org.eclipse.ui.navigator.resources
28
 org.eclipse.ui.navigator.resources,
29
 org.eclipse.core.runtime
29
Eclipse-AutoStart: true
30
Eclipse-AutoStart: true
30
Plugin-Class: org.eclipse.ui.tests.TestPlugin
31
Plugin-Class: org.eclipse.ui.tests.TestPlugin
31
Export-Package: org.eclipse.ui.tests.api
32
Export-Package: org.eclipse.ui.tests.api
(-)Eclipse UI Tests/org/eclipse/ui/tests/propertysheet/PropertySheetTestSuite.java (+4 lines)
Lines 30-35 Link Here
30
     * Construct the test suite.
30
     * Construct the test suite.
31
     */
31
     */
32
    public PropertySheetTestSuite() {
32
    public PropertySheetTestSuite() {
33
        addTest(new TestSuite(PropertyShowInContextTest.class));
34
        addTest(new TestSuite(MultiInstancePropertySheetTest.class));
35
        addTest(new TestSuite(ShowInPropertySheetTest.class));
36
        addTest(new TestSuite(NewPropertySheetHandlerTest.class));
33
        addTest(new TestSuite(PropertySheetAuto.class));
37
        addTest(new TestSuite(PropertySheetAuto.class));
34
        addTest(new TestSuite(ComboBoxPropertyDescriptorTest.class));
38
        addTest(new TestSuite(ComboBoxPropertyDescriptorTest.class));
35
    }
39
    }
(-)Eclipse UI Tests/org/eclipse/ui/tests/propertysheet/PropertySheetAuto.java (-1 / +3 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.tests.propertysheet;
12
package org.eclipse.ui.tests.propertysheet;
12
13
Lines 16-21 Link Here
16
import org.eclipse.jface.viewers.StructuredSelection;
17
import org.eclipse.jface.viewers.StructuredSelection;
17
import org.eclipse.swt.graphics.RGB;
18
import org.eclipse.swt.graphics.RGB;
18
import org.eclipse.swt.widgets.Display;
19
import org.eclipse.swt.widgets.Display;
20
import org.eclipse.ui.IPageLayout;
19
import org.eclipse.ui.ISaveablePart;
21
import org.eclipse.ui.ISaveablePart;
20
import org.eclipse.ui.IViewPart;
22
import org.eclipse.ui.IViewPart;
21
import org.eclipse.ui.IWorkbenchPage;
23
import org.eclipse.ui.IWorkbenchPage;
Lines 245-251 Link Here
245
247
246
    protected IWorkbenchPart createTestPart(IWorkbenchPage page)
248
    protected IWorkbenchPart createTestPart(IWorkbenchPage page)
247
            throws Throwable {
249
            throws Throwable {
248
        IViewPart view = page.showView("org.eclipse.ui.views.PropertySheet");
250
        IViewPart view = page.showView(IPageLayout.ID_PROP_SHEET);
249
        selectionProviderView = (SelectionProviderView) page
251
        selectionProviderView = (SelectionProviderView) page
250
                .showView(SelectionProviderView.ID);
252
                .showView(SelectionProviderView.ID);
251
        return view;
253
        return view;
(-)Eclipse (+82 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 ******************************************************************************/
11
12
package org.eclipse.ui.tests.propertysheet;
13
14
import org.eclipse.jface.action.ActionContributionItem;
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.action.IContributionItem;
17
import org.eclipse.jface.action.IToolBarManager;
18
import org.eclipse.ui.IActionBars;
19
import org.eclipse.ui.IPageLayout;
20
import org.eclipse.ui.IViewReference;
21
import org.eclipse.ui.IWorkbenchPage;
22
import org.eclipse.ui.IWorkbenchWindow;
23
import org.eclipse.ui.tests.harness.util.UITestCase;
24
import org.eclipse.ui.views.properties.PropertySheet;
25
26
/**
27
 * @since 3.4
28
 * 
29
 */
30
public abstract class AbstractPropertySheetTest extends UITestCase {
31
32
	private static final String PIN_PROPERTY_SHEET_ACTION_ID_PREFIX = "org.eclipse.ui.views.properties.PinPropertySheetAction";
33
	protected IWorkbenchPage activePage;
34
	protected PropertySheet propertySheet;
35
36
	public AbstractPropertySheetTest(String testName) {
37
		super(testName);
38
	}
39
40
	/*
41
	 * (non-Javadoc)
42
	 * 
43
	 * @see org.eclipse.ui.tests.harness.util.UITestCase#doSetUp()
44
	 */
45
	protected void doSetUp() throws Exception {
46
		super.doSetUp();
47
		IWorkbenchWindow workbenchWindow = openTestWindow();
48
		activePage = workbenchWindow.getActivePage();
49
	}
50
51
	/**
52
	 * @return the count of PropertySheets
53
	 */
54
	protected int countPropertySheetViews() {
55
		int count = 0;
56
		IViewReference[] views = activePage.getViewReferences();
57
		for (int i = 0; i < views.length; i++) {
58
			IViewReference ref = views[i];
59
			if (ref.getId().equals(IPageLayout.ID_PROP_SHEET)) {
60
				count++;
61
			}
62
		}
63
		return count;
64
	}
65
66
	protected IAction getPinPropertySheetAction(PropertySheet propertySheet) {
67
		IActionBars actionBars = propertySheet.getViewSite().getActionBars();
68
		IToolBarManager toolBarManager = actionBars.getToolBarManager();
69
		IContributionItem[] items = toolBarManager.getItems();
70
		for (int i = 0; i < items.length; i++) {
71
			IContributionItem contributionItem = items[i];
72
			if (contributionItem.getId() != null
73
					&& contributionItem.getId().startsWith(
74
							PIN_PROPERTY_SHEET_ACTION_ID_PREFIX)) {
75
				IAction action = ((ActionContributionItem) contributionItem)
76
						.getAction();
77
				return action;
78
			}
79
		}
80
		return null;
81
	}
82
}
(-)Eclipse (+244 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 ******************************************************************************/
11
12
package org.eclipse.ui.tests.propertysheet;
13
14
import org.eclipse.jface.viewers.ISelection;
15
import org.eclipse.jface.viewers.StructuredSelection;
16
import org.eclipse.ui.IPageLayout;
17
import org.eclipse.ui.IViewPart;
18
import org.eclipse.ui.PartInitException;
19
import org.eclipse.ui.part.ShowInContext;
20
import org.eclipse.ui.views.properties.PropertyShowInContext;
21
22
/**
23
 * @since 3.5
24
 * 
25
 */
26
public class PropertyShowInContextTest extends AbstractPropertySheetTest {
27
28
	public PropertyShowInContextTest(String testName) {
29
		super(testName);
30
	}
31
32
	/**
33
	 * Test method for
34
	 * {@link org.eclipse.ui.views.properties.PropertyShowInContext#hashCode()}.
35
	 */
36
	public final void testHashCode() {
37
		ShowInContext psc1 = new PropertyShowInContext(null, (ISelection) null);
38
		ShowInContext psc2 = new PropertyShowInContext(null, (ISelection) null);
39
		assertEquals(psc1.hashCode(), psc2.hashCode());
40
	}
41
42
	/**
43
	 * Test method for
44
	 * {@link org.eclipse.ui.views.properties.PropertyShowInContext#hashCode()}.
45
	 */
46
	public final void testHashCode2() {
47
		ShowInContext psc1 = new PropertyShowInContext(null,
48
				StructuredSelection.EMPTY);
49
		ShowInContext psc2 = new PropertyShowInContext(null,
50
				StructuredSelection.EMPTY);
51
		assertEquals(psc1.hashCode(), psc2.hashCode());
52
	}
53
54
	/**
55
	 * Test method for
56
	 * {@link org.eclipse.ui.views.properties.PropertyShowInContext#hashCode()}.
57
	 * 
58
	 * @throws PartInitException
59
	 */
60
	public final void testHashCode3() throws PartInitException {
61
		IViewPart showView = activePage.showView(IPageLayout.ID_PROP_SHEET);
62
		ShowInContext psc1 = new PropertyShowInContext(showView,
63
				StructuredSelection.EMPTY);
64
		ShowInContext psc2 = new PropertyShowInContext(showView,
65
				StructuredSelection.EMPTY);
66
		assertEquals(psc1.hashCode(), psc2.hashCode());
67
		psc2.setSelection(new StructuredSelection(new Object()));
68
		assertFalse(psc1.hashCode() == psc2.hashCode());
69
	}
70
71
	/**
72
	 * Test method for
73
	 * {@link org.eclipse.ui.views.properties.PropertyShowInContext#hashCode()}.
74
	 * 
75
	 * @throws PartInitException
76
	 */
77
	public final void testHashCode4() throws PartInitException {
78
		IViewPart showView = activePage.showView(IPageLayout.ID_PROP_SHEET);
79
		ShowInContext psc1 = new PropertyShowInContext(showView,
80
				new ShowInContext(null, null));
81
		PropertyShowInContext psc2 = new PropertyShowInContext(showView,
82
				new ShowInContext(null, null));
83
		assertEquals(psc1.hashCode(), psc2.hashCode());
84
85
		psc2.setPart(null);
86
		assertFalse(psc1.hashCode() == psc2.hashCode());
87
	}
88
89
	/**
90
	 * Test method for
91
	 * {@link org.eclipse.ui.views.properties.PropertyShowInContext#hashCode()}.
92
	 * 
93
	 * @throws PartInitException
94
	 */
95
	public final void testHashCode5() throws PartInitException {
96
		IViewPart showView = activePage.showView(IPageLayout.ID_PROP_SHEET);
97
		ShowInContext showInContext = new ShowInContext(null, null);
98
		ShowInContext psc1 = new PropertyShowInContext(showView, showInContext);
99
		ShowInContext psc2 = new PropertyShowInContext(showView, showInContext);
100
		assertEquals(psc1.hashCode(), psc2.hashCode());
101
	}
102
103
	/**
104
	 * Test method for
105
	 * {@link org.eclipse.ui.views.properties.PropertyShowInContext#hashCode()}.
106
	 * 
107
	 * @throws PartInitException
108
	 */
109
	public final void testHashCode6() throws PartInitException {
110
		IViewPart showView = activePage.showView(IPageLayout.ID_PROP_SHEET);
111
		ShowInContext psc1 = new PropertyShowInContext(showView,
112
				new ShowInContext(new Object(), null));
113
		ShowInContext psc2 = new PropertyShowInContext(showView,
114
				new ShowInContext(null, null));
115
		assertFalse(psc1.hashCode() == psc2.hashCode());
116
	}
117
118
	/**
119
	 * Test method for
120
	 * {@link org.eclipse.ui.views.properties.PropertyShowInContext#hashCode()}.
121
	 * 
122
	 * @throws PartInitException
123
	 */
124
	public final void testHashCode7() throws PartInitException {
125
		IViewPart showView = activePage.showView(IPageLayout.ID_PROP_SHEET);
126
		ShowInContext psc1 = new PropertyShowInContext(showView,
127
				new ShowInContext(null, null));
128
		ShowInContext psc2 = new PropertyShowInContext(showView,
129
				new ShowInContext(null, StructuredSelection.EMPTY));
130
		assertFalse(psc1.hashCode() == psc2.hashCode());
131
	}
132
133
	/**
134
	 * Test method for
135
	 * {@link org.eclipse.ui.views.properties.PropertyShowInContext#equals(Object)}
136
	 * .
137
	 */
138
	public final void testEquals() {
139
		ShowInContext psc1 = new PropertyShowInContext(null,
140
				StructuredSelection.EMPTY);
141
		psc1.setSelection(null);
142
		ShowInContext psc2 = new PropertyShowInContext(null,
143
				StructuredSelection.EMPTY);
144
		psc2.setSelection(null);
145
		assertEquals(psc1, psc2);
146
	}
147
148
	/**
149
	 * Test method for
150
	 * {@link org.eclipse.ui.views.properties.PropertyShowInContext#equals(Object)}
151
	 * .
152
	 */
153
	public final void testEquals2() {
154
		ShowInContext psc1 = new PropertyShowInContext(null,
155
				StructuredSelection.EMPTY);
156
		ShowInContext psc2 = new PropertyShowInContext(null,
157
				StructuredSelection.EMPTY);
158
		assertEquals(psc1, psc2);
159
	}
160
161
	/**
162
	 * Test method for
163
	 * {@link org.eclipse.ui.views.properties.PropertyShowInContext#equals(Object)}
164
	 * .
165
	 * 
166
	 * @throws PartInitException
167
	 */
168
	public final void testEquals3() throws PartInitException {
169
		IViewPart showView = activePage.showView(IPageLayout.ID_PROP_SHEET);
170
		ShowInContext psc1 = new PropertyShowInContext(showView,
171
				StructuredSelection.EMPTY);
172
		ShowInContext psc2 = new PropertyShowInContext(showView,
173
				StructuredSelection.EMPTY);
174
		assertEquals(psc1, psc2);
175
		psc2.setSelection(new StructuredSelection(new Object()));
176
		assertFalse(psc1.equals(psc2));
177
	}
178
179
	/**
180
	 * Test method for
181
	 * {@link org.eclipse.ui.views.properties.PropertyShowInContext#equals(Object)}
182
	 * .
183
	 * 
184
	 * @throws PartInitException
185
	 */
186
	public final void testEquals4() throws PartInitException {
187
		IViewPart showView = activePage.showView(IPageLayout.ID_PROP_SHEET);
188
		ShowInContext psc1 = new PropertyShowInContext(showView,
189
				new ShowInContext(null, null));
190
		PropertyShowInContext psc2 = new PropertyShowInContext(showView,
191
				new ShowInContext(null, null));
192
		assertEquals(psc1, psc2);
193
194
		psc2.setPart(null);
195
		assertFalse(psc1.equals(psc2));
196
	}
197
198
	/**
199
	 * Test method for
200
	 * {@link org.eclipse.ui.views.properties.PropertyShowInContext#equals(Object)}
201
	 * .
202
	 * 
203
	 * @throws PartInitException
204
	 */
205
	public final void testEquals5() throws PartInitException {
206
		IViewPart showView = activePage.showView(IPageLayout.ID_PROP_SHEET);
207
		ShowInContext showInContext = new ShowInContext(null, null);
208
		ShowInContext psc1 = new PropertyShowInContext(showView, showInContext);
209
		ShowInContext psc2 = new PropertyShowInContext(showView, showInContext);
210
		assertEquals(psc1, psc2);
211
	}
212
213
	/**
214
	 * Test method for
215
	 * {@link org.eclipse.ui.views.properties.PropertyShowInContext#equals(Object)}
216
	 * .
217
	 * 
218
	 * @throws PartInitException
219
	 */
220
	public final void testEquals6() throws PartInitException {
221
		IViewPart showView = activePage.showView(IPageLayout.ID_PROP_SHEET);
222
		ShowInContext psc1 = new PropertyShowInContext(showView,
223
				new ShowInContext(new Object(), null));
224
		ShowInContext psc2 = new PropertyShowInContext(showView,
225
				new ShowInContext(null, null));
226
		assertFalse(psc1.equals(psc2));
227
	}
228
229
	/**
230
	 * Test method for
231
	 * {@link org.eclipse.ui.views.properties.PropertyShowInContext#equals(Object)}
232
	 * .
233
	 * 
234
	 * @throws PartInitException
235
	 */
236
	public final void testEquals7() throws PartInitException {
237
		IViewPart showView = activePage.showView(IPageLayout.ID_PROP_SHEET);
238
		ShowInContext psc1 = new PropertyShowInContext(showView,
239
				new ShowInContext(null, null));
240
		ShowInContext psc2 = new PropertyShowInContext(showView,
241
				new ShowInContext(null, StructuredSelection.EMPTY));
242
		assertFalse(psc1.equals(psc2));
243
	}
244
}
(-)Eclipse (+100 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 ******************************************************************************/
11
12
package org.eclipse.ui.tests.propertysheet;
13
14
import org.eclipse.jface.viewers.StructuredSelection;
15
import org.eclipse.ui.IPageLayout;
16
import org.eclipse.ui.part.IShowInTarget;
17
import org.eclipse.ui.part.ShowInContext;
18
import org.eclipse.ui.views.properties.PropertySheet;
19
import org.eclipse.ui.views.properties.PropertyShowInContext;
20
21
/**
22
 * @since 3.4
23
 * 
24
 */
25
public class ShowInPropertySheetTest extends AbstractPropertySheetTest {
26
27
	public ShowInPropertySheetTest(String testName) {
28
		super(testName);
29
	}
30
31
	/*
32
	 * (non-Javadoc)
33
	 * 
34
	 * @see
35
	 * org.eclipse.ui.tests.propertysheet.AbstractPropertySheetTest#doSetUp()
36
	 */
37
	protected void doSetUp() throws Exception {
38
		super.doSetUp();
39
40
		propertySheet = (PropertySheet) activePage
41
				.showView(IPageLayout.ID_PROP_SHEET);
42
	}
43
44
	/*
45
	 * (non-Javadoc)
46
	 * 
47
	 * @see org.eclipse.ui.tests.harness.util.UITestCase#doTearDown()
48
	 */
49
	protected void doTearDown() throws Exception {
50
		super.doTearDown();
51
	}
52
53
	/**
54
	 * Tries to get the IShowInTarget adapter
55
	 */
56
	public void testGetIShowInTargetAdapter() {
57
		Object adapter = propertySheet.getAdapter(IShowInTarget.class);
58
		assertNotNull("No IShowInTarget adapter returned", adapter);
59
		assertTrue(adapter instanceof IShowInTarget);
60
	}
61
62
	/**
63
	 * Tests ShowIn PropertySheet with various inputs
64
	 */
65
	public void testShowInPropertySheet() {
66
		IShowInTarget showInTarget = (IShowInTarget) propertySheet
67
				.getAdapter(IShowInTarget.class);
68
		ShowInContext context = new PropertyShowInContext(activePage
69
				.getActivePart(), StructuredSelection.EMPTY);
70
		assertTrue(showInTarget.show(context));
71
	}
72
73
	/**
74
	 * Tests ShowIn PropertySheet with various inputs
75
	 */
76
	public void testShowInPropertySheetWithNull() {
77
		IShowInTarget showInTarget = (IShowInTarget) propertySheet
78
				.getAdapter(IShowInTarget.class);
79
		assertFalse(showInTarget.show(null));
80
	}
81
82
	/**
83
	 * Tests ShowIn PropertySheet with various inputs
84
	 */
85
	public void testShowInPropertySheetWithNullContext() {
86
		IShowInTarget showInTarget = (IShowInTarget) propertySheet
87
				.getAdapter(IShowInTarget.class);
88
		assertFalse(showInTarget.show(new ShowInContext(null, null)));
89
	}
90
91
	/**
92
	 * Tests ShowIn PropertySheet with various inputs
93
	 */
94
	public void testShowInPropertySheetWithNullPart() {
95
		IShowInTarget showInTarget = (IShowInTarget) propertySheet
96
				.getAdapter(IShowInTarget.class);
97
		assertFalse(showInTarget.show(new ShowInContext(new Object(),
98
				StructuredSelection.EMPTY)));
99
	}
100
}
(-)Eclipse (+65 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 ******************************************************************************/
11
12
package org.eclipse.ui.tests.propertysheet;
13
14
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.ui.PartInitException;
17
import org.eclipse.ui.views.properties.NewPropertySheetHandler;
18
import org.eclipse.ui.views.properties.PropertySheet;
19
import org.eclipse.ui.views.properties.PropertyShowInContext;
20
21
/**
22
 * @since 3.5
23
 * 
24
 */
25
public class TestNewPropertySheetHandler extends NewPropertySheetHandler {
26
27
	public static final String ID = NewPropertySheetHandler.ID + "Test";
28
29
	/*
30
	 * (non-Javadoc)
31
	 * 
32
	 * @see
33
	 * org.eclipse.ui.views.properties.NewPropertySheetHandler#execute(org.eclipse
34
	 * .core.commands.ExecutionEvent)
35
	 */
36
	public Object execute(ExecutionEvent event) throws ExecutionException {
37
		return super.execute(event);
38
	}
39
40
	/*
41
	 * (non-Javadoc)
42
	 * 
43
	 * @see
44
	 * org.eclipse.ui.views.properties.NewPropertySheetHandler#getShowInContext
45
	 * (org.eclipse.core.commands.ExecutionEvent)
46
	 */
47
	public PropertyShowInContext getShowInContext(ExecutionEvent event)
48
			throws ExecutionException {
49
		return super.getShowInContext(event);
50
	}
51
52
	/*
53
	 * (non-Javadoc)
54
	 * 
55
	 * @see
56
	 * org.eclipse.ui.views.properties.NewPropertySheetHandler#findPropertySheet
57
	 * (org.eclipse.core.commands.ExecutionEvent,
58
	 * org.eclipse.ui.views.properties.PropertyShowInContext)
59
	 */
60
	protected PropertySheet findPropertySheet(ExecutionEvent event,
61
			PropertyShowInContext context) throws PartInitException,
62
			ExecutionException {
63
		return super.findPropertySheet(event, context);
64
	}
65
}
(-)Eclipse (+79 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant  and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 ******************************************************************************/
11
12
package org.eclipse.ui.tests.propertysheet;
13
14
import org.eclipse.core.runtime.IAdapterFactory;
15
import org.eclipse.jface.viewers.ISelection;
16
import org.eclipse.ui.IWorkbenchPart;
17
import org.eclipse.ui.views.properties.IPropertySheetPage;
18
import org.eclipse.ui.views.properties.PropertySheetPage;
19
20
/**
21
 * @since 3.4
22
 * 
23
 */
24
public class TestPropertySheetPage extends PropertySheetPage implements
25
		IPropertySheetPage, IAdapterFactory {
26
27
	private ISelection fSelection;
28
	private IWorkbenchPart fPart;
29
30
	/*
31
	 * (non-Javadoc)
32
	 * 
33
	 * @see
34
	 * org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object,
35
	 * java.lang.Class)
36
	 */
37
	public Object getAdapter(Object adaptableObject, Class adapterType) {
38
		// singleton cleanup
39
		fSelection = null;
40
		fPart = null;
41
		return this;
42
	}
43
44
	/*
45
	 * (non-Javadoc)
46
	 * 
47
	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
48
	 */
49
	public Class[] getAdapterList() {
50
		return new Class[] { IPropertySheetPage.class };
51
	}
52
53
	/*
54
	 * (non-Javadoc)
55
	 * 
56
	 * @see
57
	 * org.eclipse.ui.views.properties.PropertySheetPage#selectionChanged(org
58
	 * .eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
59
	 */
60
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
61
		super.selectionChanged(part, selection);
62
		fPart = part;
63
		fSelection = selection;
64
	}
65
66
	/**
67
	 * @return Returns the selection.
68
	 */
69
	public ISelection getSelection() {
70
		return fSelection;
71
	}
72
73
	/**
74
	 * @return Returns the part.
75
	 */
76
	public IWorkbenchPart getPart() {
77
		return fPart;
78
	}
79
}
(-)Eclipse (+94 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 ******************************************************************************/
11
12
package org.eclipse.ui.tests.session;
13
14
import junit.framework.TestCase;
15
import junit.framework.TestSuite;
16
17
import org.eclipse.ui.IPageLayout;
18
import org.eclipse.ui.IViewPart;
19
import org.eclipse.ui.IViewReference;
20
import org.eclipse.ui.IWorkbench;
21
import org.eclipse.ui.IWorkbenchPage;
22
import org.eclipse.ui.PartInitException;
23
import org.eclipse.ui.PlatformUI;
24
import org.eclipse.ui.views.properties.PropertySheet;
25
26
/**
27
 * The secondary property sheets should be closed so there aren't restored in
28
 * the next workbench session.
29
 * 
30
 * @since 3.4
31
 */
32
public class NonRestorablePropertySheetTest extends TestCase {
33
34
	public static TestSuite suite() {
35
		return new TestSuite(NonRestorablePropertySheetTest.class);
36
	}
37
38
	public NonRestorablePropertySheetTest(String testName) {
39
		super(testName);
40
	}
41
42
	/**
43
	 * This is the first part instantiates a bunch of property sheets
44
	 * 
45
	 * @throws PartInitException
46
	 */
47
	public void test01ActivateView() throws PartInitException {
48
		final IWorkbench workbench = PlatformUI.getWorkbench();
49
		final IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
50
				.getActivePage();
51
52
		IViewPart part = page.showView(IPageLayout.ID_PROP_SHEET);
53
		assertNotNull(part);
54
		assertTrue(part instanceof PropertySheet);
55
56
		for (int j = 0; j < 3; j++) {
57
			try {
58
				page.showView(IPageLayout.ID_PROP_SHEET, "#" + j,
59
						IWorkbenchPage.VIEW_ACTIVATE);
60
			} catch (PartInitException e) {
61
				fail(e.getMessage());
62
			}
63
		}
64
		assertTrue(countPropertySheetViews(page) == 4);
65
	}
66
67
	/**
68
	 * In the second session the property sheet views with secondary ids
69
	 * shouldn't be instantiated.
70
	 * 
71
	 * @throws PartInitException
72
	 */
73
	public void test02SecondOpening() throws PartInitException {
74
		final IWorkbench workbench = PlatformUI.getWorkbench();
75
		final IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
76
				.getActivePage();
77
78
		assertTrue(countPropertySheetViews(page) == 1);
79
	}
80
81
	// simple counts how many property sheet instances are open
82
	private int countPropertySheetViews(final IWorkbenchPage page) {
83
		int count = 0;
84
		IViewReference[] views = page.getViewReferences();
85
		for (int i = 0; i < views.length; i++) {
86
			IViewReference ref = views[i];
87
			if (ref.getId().equals(IPageLayout.ID_PROP_SHEET)) {
88
				count++;
89
			}
90
		}
91
		return count;
92
	}
93
94
}
(-)Eclipse (+276 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 ******************************************************************************/
11
12
package org.eclipse.ui.tests.propertysheet;
13
14
import org.eclipse.core.commands.ExecutionException;
15
import org.eclipse.core.commands.NotEnabledException;
16
import org.eclipse.core.commands.NotHandledException;
17
import org.eclipse.core.commands.common.NotDefinedException;
18
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.jface.action.IAction;
20
import org.eclipse.swt.widgets.Event;
21
import org.eclipse.ui.IPageLayout;
22
import org.eclipse.ui.IWorkbenchPage;
23
import org.eclipse.ui.IWorkbenchPart;
24
import org.eclipse.ui.PartInitException;
25
import org.eclipse.ui.PlatformUI;
26
import org.eclipse.ui.handlers.IHandlerService;
27
import org.eclipse.ui.tests.SelectionProviderView;
28
import org.eclipse.ui.tests.session.NonRestorableView;
29
import org.eclipse.ui.views.properties.NewPropertySheetHandler;
30
import org.eclipse.ui.views.properties.PropertySheet;
31
import org.eclipse.ui.views.properties.PropertySheetPage;
32
33
/**
34
 * @since 3.4
35
 */
36
public class MultiInstancePropertySheetTest extends AbstractPropertySheetTest {
37
38
	/**
39
	 * TestPropertySheetPage exposes certain members for testability
40
	 */
41
	private TestPropertySheetPage testPropertySheetPage = new TestPropertySheetPage();
42
	private SelectionProviderView selectionProviderView;
43
44
	public MultiInstancePropertySheetTest(String testName) {
45
		super(testName);
46
	}
47
48
	/*
49
	 * (non-Javadoc)
50
	 * 
51
	 * @see
52
	 * org.eclipse.ui.tests.propertysheet.AbstractPropertySheetTest#doSetUp()
53
	 */
54
	protected void doSetUp() throws Exception {
55
		super.doSetUp();
56
		// open the property sheet with the TestPropertySheetPage
57
		Platform.getAdapterManager().registerAdapters(testPropertySheetPage,
58
				PropertySheet.class);
59
		propertySheet = (PropertySheet) activePage
60
				.showView(IPageLayout.ID_PROP_SHEET);
61
62
		selectionProviderView = (SelectionProviderView) activePage
63
				.showView(SelectionProviderView.ID);
64
	}
65
66
	/*
67
	 * (non-Javadoc)
68
	 * 
69
	 * @see org.eclipse.ui.tests.harness.util.UITestCase#doTearDown()
70
	 */
71
	protected void doTearDown() throws Exception {
72
		super.doTearDown();
73
		Platform.getAdapterManager().unregisterAdapters(testPropertySheetPage,
74
				PropertySheet.class);
75
	}
76
77
	/**
78
	 * The if the registered {@link TestPropertySheetPage} is set as the default
79
	 * page of the PropertySheet
80
	 * 
81
	 * @throws PartInitException
82
	 */
83
	public void testDefaultPage() throws PartInitException {
84
		PropertySheet propertySheet = (PropertySheet) activePage
85
				.showView(IPageLayout.ID_PROP_SHEET);
86
		assertTrue(propertySheet.getCurrentPage() instanceof PropertySheetPage);
87
	}
88
89
	/**
90
	 * Test if the registered {@link TestPropertySheetPage} is set as the
91
	 * default page of the PropertyShecet
92
	 * 
93
	 * @throws PartInitException
94
	 */
95
	public void testDefaultPageAdapter() throws PartInitException {
96
		Platform.getAdapterManager().registerAdapters(testPropertySheetPage,
97
				PropertySheet.class);
98
		PropertySheet propertySheet = (PropertySheet) activePage
99
				.showView(IPageLayout.ID_PROP_SHEET);
100
		assertTrue(propertySheet.getCurrentPage() instanceof TestPropertySheetPage);
101
	}
102
103
	/**
104
	 * Test if the PropertySheet allows multiple instances
105
	 * 
106
	 * @throws PartInitException
107
	 */
108
	public void testAllowsMultiple() throws PartInitException {
109
		activePage.showView(IPageLayout.ID_PROP_SHEET);
110
		try {
111
			activePage.showView(IPageLayout.ID_PROP_SHEET, "aSecondaryId",
112
					IWorkbenchPage.VIEW_ACTIVATE);
113
		} catch (PartInitException e) {
114
			fail(e.getMessage());
115
		}
116
	}
117
118
	/**
119
	 * Test if the PropertySheet follows selection
120
	 * 
121
	 * @throws Throwable
122
	 */
123
	public void testFollowsSelection() throws Throwable {
124
		// selection before selection changes
125
		TestPropertySheetPage firstPage = (TestPropertySheetPage) propertySheet
126
				.getCurrentPage();
127
		Object firstSelection = firstPage.getSelection();
128
		assertNotNull(firstSelection);
129
130
		// change the selection explicitly
131
		selectionProviderView.setSelection(new Object());
132
		TestPropertySheetPage secondPage = (TestPropertySheetPage) propertySheet
133
				.getCurrentPage();
134
135
		assertNotSame("PropertySheet hasn't changed selection", firstSelection,
136
				secondPage.getSelection());
137
	}
138
139
	/**
140
	 * Test if the PropertySheet follows part events
141
	 * 
142
	 * @throws Throwable
143
	 */
144
	public void testFollowsParts() throws Throwable {
145
		// selection before selection changes
146
		TestPropertySheetPage firstPage = (TestPropertySheetPage) propertySheet
147
				.getCurrentPage();
148
		Object firstPart = firstPage.getPart();
149
		assertNotNull(firstPart);
150
151
		// change the part explicitly (reusing the NonRestorableView here)
152
		TestPropertySheetPage testPropertySheetPage2 = new TestPropertySheetPage();
153
		Platform.getAdapterManager().registerAdapters(testPropertySheetPage2,
154
				org.eclipse.ui.tests.session.NonRestorableView.class);
155
		activePage.showView(NonRestorableView.ID);
156
157
		TestPropertySheetPage secondPage = (TestPropertySheetPage) propertySheet
158
				.getCurrentPage();
159
160
		assertEquals(testPropertySheetPage2, secondPage);
161
		assertNotSame("PropertySheet hasn't changed selection", firstPart,
162
				secondPage.getSelection());
163
	}
164
165
	/**
166
	 * Test if pinning works in the PropertySheet
167
	 * 
168
	 * @throws Throwable
169
	 */
170
	public void testPinning() throws Throwable {
171
		// execute the pin action on the property sheet
172
		IAction action = getPinPropertySheetAction(propertySheet);
173
		action.setChecked(true);
174
175
		// get the content of the pinned property sheet for later comparison
176
		TestPropertySheetPage firstPage = (TestPropertySheetPage) propertySheet
177
				.getCurrentPage();
178
		assertNotNull(firstPage);
179
		Object firstSelection = firstPage.getSelection();
180
		assertNotNull(firstSelection);
181
		IWorkbenchPart firstPart = firstPage.getPart();
182
		assertNotNull(firstPart);
183
184
		// change the selection/part
185
		selectionProviderView.setSelection(new Object());
186
		TestPropertySheetPage testPropertySheetPage2 = new TestPropertySheetPage();
187
		Platform.getAdapterManager().registerAdapters(testPropertySheetPage2,
188
				org.eclipse.ui.tests.session.NonRestorableView.class);
189
		activePage.showView(NonRestorableView.ID);
190
191
		TestPropertySheetPage secondPage = (TestPropertySheetPage) propertySheet
192
				.getCurrentPage();
193
		assertEquals("PropertySheet has changed page", firstPage, secondPage);
194
		assertEquals("PropertySheetPage has changed selection", firstSelection,
195
				secondPage.getSelection());
196
		assertEquals("PropertySheetPage has changed part", firstPart,
197
				secondPage.getPart());
198
	}
199
200
	/**
201
	 * Test if the PropertySheet unpinns if the contributing part is closed
202
	 * 
203
	 * @throws Throwable
204
	 */
205
	public void testUnpinningWhenPinnedPartIsClosed() throws Throwable {
206
		// execute the pin action on the property sheet
207
		IAction action = getPinPropertySheetAction(propertySheet);
208
		action.setChecked(true);
209
210
		// close the part the property sheet is pinned to
211
		activePage.hideView(selectionProviderView);
212
213
		// the action and therefore the property sheet should be unpinned
214
		assertFalse(action.isChecked());
215
	}
216
217
	/**
218
	 * Test if the PropertySheet's new handler creates a new instance
219
	 * 
220
	 * @throws NotHandledException
221
	 * @throws NotEnabledException
222
	 * @throws NotDefinedException
223
	 * @throws ExecutionException
224
	 */
225
	public void testNewPropertySheet() throws ExecutionException,
226
			NotDefinedException, NotEnabledException, NotHandledException {
227
		assertTrue(countPropertySheetViews() == 1);
228
		executeNewPropertySheetHandler();
229
		assertTrue(countPropertySheetViews() == 2);
230
	}
231
232
	/**
233
	 * @throws ExecutionException
234
	 * @throws NotDefinedException
235
	 * @throws NotEnabledException
236
	 * @throws NotHandledException
237
	 */
238
	private void executeNewPropertySheetHandler() throws ExecutionException,
239
			NotDefinedException, NotEnabledException, NotHandledException {
240
241
		// the propertysheet is the active part if its view toolbar command gets
242
		// pressed
243
		activePage.activate(propertySheet);
244
245
		IHandlerService handlerService = (IHandlerService) PlatformUI
246
				.getWorkbench().getService(IHandlerService.class);
247
		Event event = new Event();
248
		handlerService.executeCommand(NewPropertySheetHandler.ID, event);
249
	}
250
251
	/**
252
	 * Test if the PropertySheet pins the parent if a second instance is opened
253
	 * 
254
	 * @throws NotHandledException
255
	 * @throws NotEnabledException
256
	 * @throws NotDefinedException
257
	 * @throws ExecutionException
258
	 */
259
	public void testParentIsPinned() throws ExecutionException,
260
			NotDefinedException, NotEnabledException, NotHandledException {
261
		executeNewPropertySheetHandler();
262
263
		IAction pinAction = getPinPropertySheetAction(propertySheet);
264
		assertTrue("Parent property sheet isn't pinned", pinAction.isChecked());
265
	}
266
267
	/**
268
	 * Test if the PropertySheet pins the parent if a second instance is opened
269
	 * 
270
	 * @throws Throwable
271
	 */
272
	public void testPinningWithMultipleInstances() throws Throwable {
273
		executeNewPropertySheetHandler();
274
		testPinning();
275
	}
276
}
(-)Eclipse (+289 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Versant Corp. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103
10
 ******************************************************************************/
11
12
package org.eclipse.ui.tests.propertysheet;
13
14
import java.util.HashMap;
15
16
import org.eclipse.core.commands.Command;
17
import org.eclipse.core.commands.ExecutionEvent;
18
import org.eclipse.core.commands.ExecutionException;
19
import org.eclipse.core.expressions.IEvaluationContext;
20
import org.eclipse.core.runtime.IAdapterFactory;
21
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.jface.viewers.StructuredSelection;
23
import org.eclipse.ui.IPageLayout;
24
import org.eclipse.ui.IViewPart;
25
import org.eclipse.ui.PartInitException;
26
import org.eclipse.ui.PlatformUI;
27
import org.eclipse.ui.commands.ICommandService;
28
import org.eclipse.ui.handlers.IHandlerService;
29
import org.eclipse.ui.part.IShowInSource;
30
import org.eclipse.ui.part.ShowInContext;
31
import org.eclipse.ui.tests.SelectionProviderView;
32
import org.eclipse.ui.views.properties.PropertySheet;
33
import org.eclipse.ui.views.properties.PropertyShowInContext;
34
35
/**
36
 * @since 3.5
37
 * 
38
 */
39
public class NewPropertySheetHandlerTest extends AbstractPropertySheetTest {
40
41
	private TestNewPropertySheetHandler testNewPropertySheetHandler;
42
43
	public NewPropertySheetHandlerTest(String testName) {
44
		super(testName);
45
	}
46
47
	/*
48
	 * (non-Javadoc)
49
	 * 
50
	 * @see
51
	 * org.eclipse.ui.tests.propertysheet.AbstractPropertySheetTest#doSetUp()
52
	 */
53
	protected void doSetUp() throws Exception {
54
		super.doSetUp();
55
		testNewPropertySheetHandler = new TestNewPropertySheetHandler();
56
	}
57
58
	private ExecutionEvent getExecutionEvent() {
59
		IHandlerService handlerService = (IHandlerService) PlatformUI
60
				.getWorkbench().getService(IHandlerService.class);
61
		ICommandService commandService = (ICommandService) PlatformUI
62
				.getWorkbench().getService(ICommandService.class);
63
		IEvaluationContext evalContext = handlerService.getCurrentState();
64
		Command command = commandService
65
				.getCommand(TestNewPropertySheetHandler.ID);
66
		ExecutionEvent executionEvent = new ExecutionEvent(command,
67
				new HashMap(), null, evalContext);
68
		return executionEvent;
69
	}
70
71
	/**
72
	 * Test method for
73
	 * {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#getShowInContext(org.eclipse.core.commands.ExecutionEvent)}
74
	 * .
75
	 * 
76
	 * @throws ExecutionException
77
	 * @throws PartInitException
78
	 *             StructuredSelection.EMPTY,
79
	 */
80
	public final void testGetShowInContextFromPropertySheet()
81
			throws ExecutionException, PartInitException {
82
		activePage.showView(IPageLayout.ID_PROP_SHEET);
83
84
		PropertyShowInContext context = testNewPropertySheetHandler
85
				.getShowInContext(getExecutionEvent());
86
		assertNotNull(context);
87
		assertNull(context.getSelection());
88
		assertNull(context.getPart());
89
		assertNull(context.getInput());
90
	}
91
92
	/**
93
	 * Test method for
94
	 * {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#getShowInContext(org.eclipse.core.commands.ExecutionEvent)}
95
	 * .
96
	 * 
97
	 * @throws ExecutionException
98
	 * @throws PartInitException
99
	 */
100
	public final void testGetShowInContextFromAShowInSource()
101
			throws ExecutionException, PartInitException {
102
		IAdapterFactory factory = new IAdapterFactory() {
103
			public Object getAdapter(Object adaptableObject, Class adapterType) {
104
				return new IShowInSource() {
105
					public ShowInContext getShowInContext() {
106
						return new ShowInContext(StructuredSelection.EMPTY,
107
								StructuredSelection.EMPTY);
108
					}
109
				};
110
			}
111
112
			public Class[] getAdapterList() {
113
				return new Class[] { IShowInSource.class };
114
			}
115
		};
116
		try {
117
			SelectionProviderView selectionProviderView = (SelectionProviderView) activePage
118
					.showView(SelectionProviderView.ID);
119
			selectionProviderView.setSelection(StructuredSelection.EMPTY);
120
			Platform.getAdapterManager().registerAdapters(factory,
121
					SelectionProviderView.class);
122
123
			PropertyShowInContext context = testNewPropertySheetHandler
124
					.getShowInContext(getExecutionEvent());
125
			assertNotNull(context);
126
			assertEquals(StructuredSelection.EMPTY, context.getSelection());
127
			assertEquals(StructuredSelection.EMPTY, context.getInput());
128
			assertEquals(selectionProviderView, context.getPart());
129
		} finally {
130
			Platform.getAdapterManager().unregisterAdapters(factory);
131
		}
132
	}
133
134
	/**
135
	 * Test method for
136
	 * {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#getShowInContext(org.eclipse.core.commands.ExecutionEvent)}
137
	 * .
138
	 * 
139
	 * @throws ExecutionException
140
	 * @throws PartInitException
141
	 */
142
	public final void testGetShowInContextWithNoShowInSource()
143
			throws PartInitException, ExecutionException {
144
		SelectionProviderView selectionProviderView = (SelectionProviderView) activePage
145
				.showView(SelectionProviderView.ID);
146
		assertFalse(selectionProviderView instanceof IShowInSource);
147
		assertNull(selectionProviderView.getAdapter(IShowInSource.class));
148
149
		PropertyShowInContext context = testNewPropertySheetHandler
150
				.getShowInContext(getExecutionEvent());
151
		assertNotNull(context);
152
		assertNull(context.getSelection());
153
		assertNull(context.getInput());
154
		assertEquals(selectionProviderView, context.getPart());
155
	}
156
157
	/**
158
	 * Test method for
159
	 * {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#getShowInContext(org.eclipse.core.commands.ExecutionEvent)}
160
	 * .
161
	 */
162
	public final void testGetShowInContextWithNoActivePart() {
163
		try {
164
			testNewPropertySheetHandler.getShowInContext(getExecutionEvent());
165
		} catch (ExecutionException e) {
166
			return;
167
		}
168
		fail("Expected ExecutionException due to no active part");
169
	}
170
171
	/**
172
	 * Test method for
173
	 * {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyShowInContext)}
174
	 * .
175
	 * 
176
	 * @throws ExecutionException
177
	 * @throws PartInitException
178
	 */
179
	public final void testFindPropertySheetWithoutActivePart()
180
			throws PartInitException, ExecutionException {
181
		assertNull(PlatformUI.getWorkbench().getActiveWorkbenchWindow()
182
				.getActivePage().getActivePart());
183
184
		try {
185
			testNewPropertySheetHandler.findPropertySheet(getExecutionEvent(),
186
					new PropertyShowInContext(null, StructuredSelection.EMPTY));
187
		} catch (ExecutionException e) {
188
			return;
189
		}
190
		fail("Expected ExecutionException due to no active part");
191
	}
192
193
	/**
194
	 * Test method for
195
	 * {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyShowInContext)}
196
	 * .
197
	 * 
198
	 * @throws ExecutionException
199
	 * @throws PartInitException
200
	 */
201
	public final void testFindPropertySheetWithOtherSheetActive()
202
			throws PartInitException, ExecutionException {
203
		propertySheet = (PropertySheet) activePage
204
				.showView(IPageLayout.ID_PROP_SHEET);
205
		assertTrue(countPropertySheetViews() == 1);
206
207
		PropertySheet foundSheet = testNewPropertySheetHandler
208
				.findPropertySheet(getExecutionEvent(),
209
						new PropertyShowInContext(propertySheet,
210
								StructuredSelection.EMPTY));
211
		assertNotNull(foundSheet);
212
		assertNotSame(propertySheet, foundSheet);
213
		assertTrue(countPropertySheetViews() == 2);
214
	}
215
216
	/**
217
	 * Test method for
218
	 * {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyShowInContext)}
219
	 * .
220
	 * 
221
	 * @throws ExecutionException
222
	 * @throws PartInitException
223
	 */
224
	public final void testFindPropertySheetWithSPVActive()
225
			throws PartInitException, ExecutionException {
226
		IViewPart showView = activePage.showView(IPageLayout.ID_PROP_SHEET);
227
		IViewPart spv = activePage.showView(SelectionProviderView.ID);
228
		assertTrue(countPropertySheetViews() == 1);
229
230
		PropertySheet foundSheet = testNewPropertySheetHandler
231
				.findPropertySheet(getExecutionEvent(),
232
						new PropertyShowInContext(spv,
233
								StructuredSelection.EMPTY));
234
		assertNotNull(foundSheet);
235
		assertEquals(showView, foundSheet);
236
		assertTrue(countPropertySheetViews() == 1);
237
	}
238
239
	/**
240
	 * Test method for
241
	 * {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyShowInContext)}
242
	 * .
243
	 * 
244
	 * @throws ExecutionException
245
	 * @throws PartInitException
246
	 */
247
	public final void testFindPropertySheetWithPinnedPSandSPVActive()
248
			throws PartInitException, ExecutionException {
249
		PropertySheet sheet = (PropertySheet) activePage
250
				.showView(IPageLayout.ID_PROP_SHEET);
251
		sheet.setPinned(true);
252
		IViewPart spv = activePage.showView(SelectionProviderView.ID);
253
		assertTrue(countPropertySheetViews() == 1);
254
255
		PropertySheet foundSheet = testNewPropertySheetHandler
256
				.findPropertySheet(getExecutionEvent(),
257
						new PropertyShowInContext(spv,
258
								StructuredSelection.EMPTY));
259
		assertNotNull(foundSheet);
260
		assertNotSame(sheet, foundSheet);
261
		assertTrue(countPropertySheetViews() == 2);
262
	}
263
264
	/**
265
	 * Test method for
266
	 * {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyShowInContext)}
267
	 * .
268
	 * 
269
	 * @throws ExecutionException
270
	 * @throws PartInitException
271
	 */
272
	public final void testFindPropertySheetWithUnpinnedPSandSPVActive()
273
			throws PartInitException, ExecutionException {
274
		PropertySheet sheet = (PropertySheet) activePage
275
				.showView(IPageLayout.ID_PROP_SHEET);
276
		IViewPart showView = activePage.showView(SelectionProviderView.ID);
277
		PropertyShowInContext context = new PropertyShowInContext(showView,
278
				StructuredSelection.EMPTY);
279
		assertTrue(sheet.show(context));
280
		sheet.setPinned(true);
281
		assertTrue(countPropertySheetViews() == 1);
282
283
		PropertySheet foundSheet = testNewPropertySheetHandler
284
				.findPropertySheet(getExecutionEvent(), context);
285
		assertNotNull(foundSheet);
286
		assertEquals(sheet, foundSheet);
287
		assertTrue(countPropertySheetViews() == 1);
288
	}
289
}

Return to bug 248103