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 (+6 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
35
New_text = &Open new property view
36
New_toolTip = Open a second property view
37
32
PropertyViewer_property = Property
38
PropertyViewer_property = Property
33
PropertyViewer_value = Value
39
PropertyViewer_value = Value
34
PropertyViewer_misc = Misc
40
PropertyViewer_misc = Misc
(-)src/org/eclipse/ui/internal/views/properties/PropertiesMessages.java (+11 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
	/** */
56
	public static String New_text;
57
	/** */
58
	public static String New_toolTip;
59
	
60
	/** */
50
	public static String PropertyViewer_property;
61
	public static String PropertyViewer_property;
51
	/** */
62
	/** */
52
	public static String PropertyViewer_value;
63
	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 (+7 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
    
43
    public static final String NEW_ACTION = PREFIX
44
    		+ "properties_new_action_context"; //$NON-NLS-1$;
45
39
    // Views
46
    // Views
40
    public static final String PROPERTY_SHEET_VIEW = PREFIX
47
    public static final String PROPERTY_SHEET_VIEW = PREFIX
41
            + "property_sheet_view_context"; //$NON-NLS-1$
48
            + "property_sheet_view_context"; //$NON-NLS-1$
(-)src/org/eclipse/ui/views/properties/PropertySheet.java (-10 / +148 lines)
Lines 7-24 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.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Status;
16
import org.eclipse.jface.action.Action;
17
import org.eclipse.jface.action.IAction;
18
import org.eclipse.jface.action.IMenuManager;
19
import org.eclipse.jface.action.IToolBarManager;
20
import org.eclipse.jface.action.Separator;
13
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.jface.viewers.ISelection;
14
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.ui.IMemento;
15
import org.eclipse.ui.ISaveablePart;
24
import org.eclipse.ui.ISaveablePart;
16
import org.eclipse.ui.ISelectionListener;
25
import org.eclipse.ui.ISelectionListener;
17
import org.eclipse.ui.IViewSite;
26
import org.eclipse.ui.IViewSite;
27
import org.eclipse.ui.IWorkbenchActionConstants;
18
import org.eclipse.ui.IWorkbenchPage;
28
import org.eclipse.ui.IWorkbenchPage;
19
import org.eclipse.ui.IWorkbenchPart;
29
import org.eclipse.ui.IWorkbenchPart;
20
import org.eclipse.ui.PartInitException;
30
import org.eclipse.ui.PartInitException;
31
import org.eclipse.ui.PlatformUI;
21
import org.eclipse.ui.internal.views.ViewsPlugin;
32
import org.eclipse.ui.internal.views.ViewsPlugin;
33
import org.eclipse.ui.internal.views.properties.PropertiesMessages;
22
import org.eclipse.ui.part.IContributedContentsView;
34
import org.eclipse.ui.part.IContributedContentsView;
23
import org.eclipse.ui.part.IPage;
35
import org.eclipse.ui.part.IPage;
24
import org.eclipse.ui.part.IPageBookViewPage;
36
import org.eclipse.ui.part.IPageBookViewPage;
Lines 73-78 Link Here
73
    private ISelection bootstrapSelection;
85
    private ISelection bootstrapSelection;
74
86
75
    /**
87
    /**
88
     * The current selection of the property sheet
89
     */
90
    private ISelection currentSelection;
91
92
    /**
93
     * The current part for which this property sheets is active
94
     */
95
	private IWorkbenchPart currentPart;
96
97
	/**
98
	 * Whether this property sheet instance is pinned or not 
99
	 */
100
	private IAction pinPropertySheetAction;
101
102
	/**
103
	 * Used to identify new property sheet instances
104
	 */
105
	//TODO create a real secondaryId in case property sheets should restore
106
	private static int SECONDARY_ID_COUNTER;
107
108
    /**
76
     * Creates a property sheet view.
109
     * Creates a property sheet view.
77
     */
110
     */
78
    public PropertySheet() {
111
    public PropertySheet() {
Lines 84-101 Link Here
84
     * Returns the default property sheet page.
117
     * Returns the default property sheet page.
85
     */
118
     */
86
    protected IPage createDefaultPage(PageBook book) {
119
    protected IPage createDefaultPage(PageBook book) {
87
        PropertySheetPage page = new PropertySheetPage();
120
        IPageBookViewPage page = (IPageBookViewPage) ViewsPlugin.getAdapter(this,
121
                IPropertySheetPage.class, false);
122
        if(page == null) {
123
        	page = new PropertySheetPage();
124
        }
88
        initPage(page);
125
        initPage(page);
89
        page.createControl(book);
126
        page.createControl(book);
90
        return page;
127
        return page;
91
    }
128
    }
92
129
93
    /**
130
	/**
94
     * The <code>PropertySheet</code> implementation of this <code>IWorkbenchPart</code>
131
     * The <code>PropertySheet</code> implementation of this <code>IWorkbenchPart</code>
95
     * method creates a <code>PageBook</code> control with its default page showing.
132
     * method creates a <code>PageBook</code> control with its default page showing.
96
     */
133
     */
97
    public void createPartControl(Composite parent) {
134
    public void createPartControl(Composite parent) {
98
        super.createPartControl(parent);
135
        super.createPartControl(parent);
136
         
137
        pinPropertySheetAction = new PinPropertySheetAction(SECONDARY_ID_COUNTER);
138
		IAction newPropertySheetAction = new NewPropertySheetAction();
139
140
		IMenuManager menuManager = getViewSite().getActionBars()
141
				.getMenuManager();
142
		menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
143
		menuManager.add(pinPropertySheetAction);
144
		menuManager.add(newPropertySheetAction);
145
146
		IToolBarManager toolBarManager = getViewSite().getActionBars()
147
				.getToolBarManager();
148
		menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
149
		toolBarManager.add(pinPropertySheetAction);
150
		toolBarManager.add(newPropertySheetAction);
151
        
99
        getSite().getPage().getWorkbenchWindow().getWorkbench().getHelpSystem()
152
        getSite().getPage().getWorkbenchWindow().getWorkbench().getHelpSystem()
100
				.setHelp(getPageBook(),
153
				.setHelp(getPageBook(),
101
						IPropertiesHelpContextIds.PROPERTY_SHEET_VIEW);
154
						IPropertiesHelpContextIds.PROPERTY_SHEET_VIEW);
Lines 116-122 Link Here
116
     * Method declared on PageBookView.
169
     * Method declared on PageBookView.
117
     */
170
     */
118
    protected PageRec doCreatePage(IWorkbenchPart part) {
171
    protected PageRec doCreatePage(IWorkbenchPart part) {
119
        // Try to get a custom property sheet page.
172
        // Try to get a custom property sheet page but not if the part is also a
173
		// PropertySheet in which case we would chain parent and child property
174
		// sheet with causes trouble if the child .
175
    	if(part instanceof PropertySheet) {
176
    		return null;
177
    	}
120
        IPropertySheetPage page = (IPropertySheetPage) ViewsPlugin.getAdapter(part,
178
        IPropertySheetPage page = (IPropertySheetPage) ViewsPlugin.getAdapter(part,
121
                IPropertySheetPage.class, false);
179
                IPropertySheetPage.class, false);
122
        if (page != null) {
180
        if (page != null) {
Lines 158-176 Link Here
158
     * Method declared on IViewPart.
216
     * Method declared on IViewPart.
159
     */
217
     */
160
    public void init(IViewSite site) throws PartInitException {
218
    public void init(IViewSite site) throws PartInitException {
161
        site.getPage().addSelectionListener(this);
219
   		site.getPage().addSelectionListener(this);
162
        super.init(site);
220
   		super.init(site);
163
    }
221
    }
164
222
165
    /* (non-Javadoc)
223
    /* (non-Javadoc)
224
	 * @see org.eclipse.ui.part.ViewPart#saveState(org.eclipse.ui.IMemento)
225
	 */
226
	public void saveState(IMemento memento) {
227
		// close all but the primary/parent property sheet
228
		String secondaryId = getViewSite().getSecondaryId();
229
		if (null == secondaryId) {
230
			super.saveState(memento);
231
		} else {
232
			getViewSite().getPage().hideView(this);
233
		}
234
	}
235
236
    /* (non-Javadoc)
166
     * Method declared on PageBookView.
237
     * Method declared on PageBookView.
167
     * The property sheet may show properties for any view other than this view.
238
     * The property sheet may show properties for any view other than this view.
168
     */
239
     */
169
    protected boolean isImportant(IWorkbenchPart part) {
240
    protected boolean isImportant(IWorkbenchPart part) {
170
        return part != this;
241
        return pinPropertySheetAction == null
242
				|| (pinPropertySheetAction != null && !pinPropertySheetAction
243
						.isChecked()) && !(part instanceof PropertySheet);
171
    }
244
    }
172
245
173
    /**
246
    /* (non-Javadoc)
247
	 * @see org.eclipse.ui.part.PageBookView#partClosed(org.eclipse.ui.IWorkbenchPart)
248
	 */
249
	public void partClosed(IWorkbenchPart part) {
250
		if (pinPropertySheetAction.isChecked() && part.equals(currentPart)) {
251
			pinPropertySheetAction.setChecked(false);
252
		}
253
		super.partClosed(part);
254
	}
255
256
	/**
174
     * The <code>PropertySheet</code> implementation of this <code>IPartListener</code>
257
     * The <code>PropertySheet</code> implementation of this <code>IPartListener</code>
175
     * method first sees if the active part is an <code>IContributedContentsView</code>
258
     * method first sees if the active part is an <code>IContributedContentsView</code>
176
     * adapter and if so, asks it for its contributing part.
259
     * adapter and if so, asks it for its contributing part.
Lines 190-195 Link Here
190
			super.partActivated(part);
273
			super.partActivated(part);
191
		}
274
		}
192
275
276
        if(isImportant(part)) {
277
        	currentPart = part;
278
        }
279
        
193
        // When the view is first opened, pass the selection to the page		
280
        // When the view is first opened, pass the selection to the page		
194
        if (bootstrapSelection != null) {
281
        if (bootstrapSelection != null) {
195
            IPropertySheetPage page = (IPropertySheetPage) getCurrentPage();
282
            IPropertySheetPage page = (IPropertySheetPage) getCurrentPage();
Lines 206-219 Link Here
206
     */
293
     */
207
    public void selectionChanged(IWorkbenchPart part, ISelection sel) {
294
    public void selectionChanged(IWorkbenchPart part, ISelection sel) {
208
        // we ignore our own selection or null selection
295
        // we ignore our own selection or null selection
209
        if (part == this || sel == null) {
296
		if (sel == null || !isImportant(part)
297
				|| (!isImportant(part) && sel.equals(currentSelection))) {
210
			return;
298
			return;
211
		}
299
		}
212
300
        
301
        currentPart = part;
302
        currentSelection = sel;
303
        
213
        // pass the selection to the page		
304
        // pass the selection to the page		
214
        IPropertySheetPage page = (IPropertySheetPage) getCurrentPage();
305
        IPropertySheetPage page = (IPropertySheetPage) getCurrentPage();
215
        if (page != null) {
306
        if (page != null) {
216
			page.selectionChanged(part, sel);
307
			page.selectionChanged(currentPart, currentSelection);
217
		}
308
		}
218
    }
309
    }
219
    
310
    
Lines 246-249 Link Here
246
		}
337
		}
247
		return null;
338
		return null;
248
	}
339
	}
340
341
	/**
342
	 * Open a new view instance with the current selection.
343
	 * @since 3.5
344
	 */
345
	private class NewPropertySheetAction extends Action {
346
347
		private NewPropertySheetAction() {
348
			super(PropertiesMessages.New_text);
349
350
			setId(NewPropertySheetAction.class.getName()
351
					+ "#" + SECONDARY_ID_COUNTER); //$NON-NLS-1$
352
			setToolTipText(PropertiesMessages.New_toolTip);
353
			setImageDescriptor(ViewsPlugin
354
					.getViewImageDescriptor("elcl16/new.gif")); //$NON-NLS-1$
355
356
			PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
357
					IPropertiesHelpContextIds.NEW_ACTION);
358
		}
359
360
		/*
361
		 * (non-Javadoc)
362
		 * 
363
		 * @see org.eclipse.jface.action.Action#run()
364
		 */
365
		public void run() {
366
			super.run();
367
			try {
368
				IWorkbenchPage workbenchPage = getViewSite().getPage();
369
370
				PropertySheet newSheet = (PropertySheet) workbenchPage
371
						.showView(
372
								getViewSite().getId(),
373
								PropertySheet.class.getName()
374
										+ "#" + ++SECONDARY_ID_COUNTER, IWorkbenchPage.VIEW_ACTIVATE); //$NON-NLS-1$
375
				newSheet.partActivated(currentPart);
376
				newSheet.selectionChanged(currentPart, currentSelection);
377
378
				// and pin this one
379
				pinPropertySheetAction.setChecked(true);
380
			} catch (PartInitException e) {
381
				ViewsPlugin.getDefault().getLog().log(
382
						new Status(IStatus.ERROR, ViewsPlugin.PLUGIN_ID,
383
								IStatus.OK, e.getMessage(), e));
384
			}
385
		}
386
	}
249
}
387
}
(-)plugin.xml (-3 / +4 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"
(-)icons/full/elcl16/pin.gif (+7 lines)
Added Link Here
1
GIF89a����2]������0t�Dv�Fw�Fx�>��>��]�Ϊ�������]�΄�ڄ�����Z��o����X��s�����������������������������������������������������������r6a.R'�>5�Xr�I}�Q�ʁ��n���������������!�8,�@�pH,�H��%KW�X��A_��p<��lc���I�r�hV/X�X8
2
�z�nD7
3
��|3�C�!!!���B6
4
""�#6D4
5
%$%%%5D*
6
&��)D
7
'(' �� D����NHA;
(-)icons/full/dlcl16/pin.gif (+2 lines)
Added Link Here
1
GIF89a���������������������������Թ����������������������������������������y�~������������������!�,\�'�di�(ڭ)�i[�z����w��#�L.
2
'�����d0La�T�.�a|���b��!�v�P���eϷ4,s���i;�,3&!;
(-)src/org/eclipse/ui/views/properties/PinPropertySheetAction.java (+42 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.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.views.ViewsPlugin;
18
import org.eclipse.ui.internal.views.properties.PropertiesMessages;
19
20
/**
21
 * Pins the properties view instance to the current selection.
22
 * @since 3.5
23
 */
24
public class PinPropertySheetAction extends Action {
25
	
26
	/**
27
	 * @param id suffix that is used to create a unique id.
28
	 */
29
	public PinPropertySheetAction(int id) {
30
		super(PropertiesMessages.Pin_text, IAction.AS_CHECK_BOX);
31
32
		setId(PinPropertySheetAction.class.getName() + "#" + id); //$NON-NLS-1$
33
		setToolTipText(PropertiesMessages.Pin_toolTip);
34
		setImageDescriptor(ViewsPlugin.getViewImageDescriptor("elcl16/pin.gif")); //$NON-NLS-1$
35
		setDisabledImageDescriptor(ViewsPlugin
36
				.getViewImageDescriptor("dlcl16/pin.gif")); //$NON-NLS-1$
37
38
		PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
39
				IPropertiesHelpContextIds.PIN_ACTION);
40
	}
41
42
}
(-)icons/full/elcl16/new.gif (+4 lines)
Added Link Here
1
GIF89a�Ft�Fu�S��Dv�Fw�Hy�S��k��l��ξ��������������v�������h��m������s������������������������������������������������������������������������������������������������������������������������������������������������Ū��������������˛�j������������������ѵ�#��#��&���������멇~`�y���������߀���������嘖�e��Q��Wjq��Z��\��K��M��O˪_��\��T��V�p��r���!�w,@w������V��H��	
2
3
TUHUU�aNORSMaw�
4
``Y_^�n�� +,]b]u�o!��)-4?WEv�p&'"26;cJq�i#�#09=dBr�s$�1:Ge<t�jJx�".�b�>��q&H�l��!��I�`�c��6�РabJ�-K֠�B�����;
(-)Eclipse UI Tests/org/eclipse/ui/tests/session/SessionTests.java (-1 / +4 lines)
Lines 100-106 Link Here
100
				Bug108033Test.class));
100
				Bug108033Test.class));
101
		addTest(new WorkbenchSessionTest("editorSessionTests",
101
		addTest(new WorkbenchSessionTest("editorSessionTests",
102
				ArbitraryPropertiesViewTest.class));
102
				ArbitraryPropertiesViewTest.class));
103
		addTest(new WorkbenchSessionTest("editorSessionTests", NonRestorableViewTest.class));
103
		addTest(new WorkbenchSessionTest("editorSessionTests",
104
				NonRestorableViewTest.class));
105
		addTest(new WorkbenchSessionTest("editorSessionTests",
106
				NonRestorablePropertySheetTest.class));
104
		addTest(new WorkbenchSessionTest("editorSessionTests",
107
		addTest(new WorkbenchSessionTest("editorSessionTests",
105
				MarkersViewColumnSizeTest.class));
108
				MarkersViewColumnSizeTest.class));
106
	}
109
	}
(-)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 (-1 / +1 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
(-)Eclipse (+68 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.5
22
 *
23
 */
24
public class TestPropertySheetPage extends PropertySheetPage implements
25
		IPropertySheetPage, IAdapterFactory {
26
27
	private ISelection fSelection;
28
	private IWorkbenchPart fPart;
29
30
	/* (non-Javadoc)
31
	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
32
	 */
33
	public Object getAdapter(Object adaptableObject, Class adapterType) {
34
		fSelection = null;
35
		fPart = null;
36
		return this;
37
	}
38
39
	/* (non-Javadoc)
40
	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
41
	 */
42
	public Class[] getAdapterList() {
43
		return new Class[]{IPropertySheetPage.class};
44
	}
45
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.ui.views.properties.PropertySheetPage#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
48
	 */
49
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
50
		super.selectionChanged(part, selection);
51
		fPart = part;
52
		fSelection = selection;
53
	}
54
	
55
	/**
56
	 * @return Returns the selection.
57
	 */
58
	public ISelection getSelection() {
59
		return fSelection;
60
	}
61
62
	/**
63
	 * @return Returns the part.
64
	 */
65
	public IWorkbenchPart getPart() {
66
		return fPart;
67
	}
68
}
(-)Eclipse (+92 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.IViewPart;
18
import org.eclipse.ui.IViewReference;
19
import org.eclipse.ui.IWorkbench;
20
import org.eclipse.ui.IWorkbenchPage;
21
import org.eclipse.ui.PartInitException;
22
import org.eclipse.ui.PlatformUI;
23
import org.eclipse.ui.views.properties.PropertySheet;
24
25
/**
26
 * The secondary property sheets should be closed so there aren't restored in the next workbench session.
27
 * 
28
 * @since 3.5
29
 */
30
public class NonRestorablePropertySheetTest extends TestCase {
31
	
32
	private static final String PROPERTY_SHEET_VIEW_ID = "org.eclipse.ui.views.PropertySheet";
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
	 * This is the first part  instantiates a bunch of property sheets
43
	 * 
44
	 * @throws PartInitException 
45
	 */
46
	public void test01ActivateView() throws PartInitException {
47
		final IWorkbench workbench = PlatformUI.getWorkbench();
48
		final IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
49
				.getActivePage();
50
51
		IViewPart part = page.showView(PROPERTY_SHEET_VIEW_ID);
52
		assertNotNull(part);
53
		assertTrue(part instanceof PropertySheet);
54
		
55
		for (int j = 0; j < 3; j++) {
56
			try {
57
				page.showView(PROPERTY_SHEET_VIEW_ID, "#" + j, IWorkbenchPage.VIEW_ACTIVATE);
58
			} catch (PartInitException e) {
59
				fail(e.getMessage());
60
			}
61
		}
62
		assertTrue(countPropertySheetViews(page) == 4);
63
	}
64
65
	/**
66
	 * In the second session the property sheet views with secondary ids shouldn't be
67
	 * instantiated.
68
	 * 
69
	 * @throws PartInitException
70
	 */
71
	public void test02SecondOpening() throws PartInitException {
72
		final IWorkbench workbench = PlatformUI.getWorkbench();
73
		final IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
74
				.getActivePage();
75
76
		assertTrue(countPropertySheetViews(page) == 1);
77
	}
78
79
	// simple counts how many property sheet instances are open
80
	private int countPropertySheetViews(final IWorkbenchPage page) {
81
		int count = 0;
82
		IViewReference[] views = page.getViewReferences();
83
		for (int i = 0; i < views.length; i++) {
84
			IViewReference ref = views[i];
85
			if (ref.getId().equals(PROPERTY_SHEET_VIEW_ID)) {
86
				count++;
87
			}
88
		}
89
		return count;
90
	}
91
92
}
(-)Eclipse (+229 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.runtime.Platform;
15
import org.eclipse.jface.action.ActionContributionItem;
16
import org.eclipse.jface.action.IAction;
17
import org.eclipse.jface.action.IContributionItem;
18
import org.eclipse.jface.action.IToolBarManager;
19
import org.eclipse.ui.IActionBars;
20
import org.eclipse.ui.IWorkbenchPage;
21
import org.eclipse.ui.IWorkbenchPart;
22
import org.eclipse.ui.IWorkbenchWindow;
23
import org.eclipse.ui.PartInitException;
24
import org.eclipse.ui.tests.SelectionProviderView;
25
import org.eclipse.ui.tests.harness.util.UITestCase;
26
import org.eclipse.ui.tests.session.NonRestorableView;
27
import org.eclipse.ui.views.properties.PropertySheet;
28
import org.eclipse.ui.views.properties.PropertySheetPage;
29
30
/**
31
 * @since 3.5
32
 */
33
public class MultiInstancePropertySheetTest extends UITestCase {
34
35
	private static final String PIN_PROPERTY_SHEET_ACTION_ID_PREFIX = "org.eclipse.ui.views.properties.PinPropertySheetAction";
36
//	private static final String NEW_PROPERTY_SHEET_ACTION_ID_PREFIX = "org.eclipse.ui.views.properties.PropertySheet$NewPropertySheetAction";
37
	private static final String PROPERTY_SHEET_ID = "org.eclipse.ui.views.PropertySheet";
38
39
	/**
40
	 * TestPropertySheetPage exposes certain members for testability
41
	 */
42
	private TestPropertySheetPage testPropertySheetPage = new TestPropertySheetPage();
43
	private IWorkbenchPage activePage;
44
	private PropertySheet propertySheet;
45
	private SelectionProviderView selectionProviderView;
46
47
	/**
48
	 * @param testName
49
	 */
50
	public MultiInstancePropertySheetTest(String testName) {
51
		super(testName);
52
	}
53
	
54
    /* (non-Javadoc)
55
     * @see org.eclipse.ui.tests.harness.util.UITestCase#doSetUp()
56
     */
57
    protected void doSetUp() throws Exception {
58
        super.doSetUp();
59
        IWorkbenchWindow workbenchWindow = openTestWindow();
60
        activePage = workbenchWindow.getActivePage();
61
62
		// open the property sheet with the TestPropertySheetPage
63
		Platform.getAdapterManager().registerAdapters(testPropertySheetPage,
64
				PropertySheet.class);
65
		propertySheet = (PropertySheet) activePage
66
				.showView(PROPERTY_SHEET_ID);
67
68
        selectionProviderView = (SelectionProviderView) activePage
69
        .showView(SelectionProviderView.ID);
70
    }
71
    
72
	/*
73
	 * (non-Javadoc)
74
	 * @see org.eclipse.ui.tests.harness.util.UITestCase#doTearDown()
75
	 */
76
	protected void doTearDown() throws Exception {
77
		super.doTearDown();
78
		Platform.getAdapterManager().unregisterAdapters(testPropertySheetPage,
79
				PropertySheet.class);
80
	}
81
	
82
	/**
83
	 * @param propertySheet
84
	 */
85
	private IAction getPropertySheetAction(PropertySheet propertySheet,
86
			String id) {
87
		IActionBars actionBars = propertySheet.getViewSite().getActionBars();
88
		IToolBarManager toolBarManager = actionBars.getToolBarManager();
89
		IContributionItem[] items = toolBarManager.getItems();
90
		for (int i = 0; i < items.length; i++) {
91
			IContributionItem contributionItem = items[i];
92
			if (contributionItem.getId() != null && contributionItem.getId().startsWith(id)) {
93
				IAction action = ((ActionContributionItem) contributionItem)
94
				.getAction();
95
				return action;
96
			}
97
		}
98
		return null;
99
	}
100
101
	/**
102
	 * The if the registered {@link TestPropertySheetPage} is set as the default
103
	 * page of the PropertySheet
104
	 * 
105
	 * @throws PartInitException
106
	 */
107
	public void testDefaultPage() throws PartInitException {
108
		PropertySheet propertySheet = (PropertySheet) activePage
109
				.showView(PROPERTY_SHEET_ID);
110
		assertTrue(propertySheet.getCurrentPage() instanceof PropertySheetPage);
111
	}
112
113
	/**
114
	 * Test if the registered {@link TestPropertySheetPage} is set as the
115
	 * default page of the PropertySheet
116
	 * 
117
	 * @throws PartInitException
118
	 */
119
	public void testDefaultPageAdapter() throws PartInitException {
120
		Platform.getAdapterManager().registerAdapters(testPropertySheetPage,
121
				PropertySheet.class);
122
		PropertySheet propertySheet = (PropertySheet) activePage
123
				.showView(PROPERTY_SHEET_ID);
124
		assertTrue(propertySheet.getCurrentPage() instanceof TestPropertySheetPage);
125
	}
126
127
	/**
128
	 * Test if the PropertySheet allows multiple instances
129
	 * 
130
	 * @throws PartInitException
131
	 */
132
	public void testAllowsMultiple() throws PartInitException {
133
		activePage.showView(PROPERTY_SHEET_ID);
134
		try {
135
			activePage.showView(PROPERTY_SHEET_ID,
136
					"aSecondaryId", IWorkbenchPage.VIEW_ACTIVATE);
137
		} catch (PartInitException e) {
138
			fail(e.getMessage());
139
		}
140
	}
141
142
	// make sure the property sheet follows selection/part changes
143
	public void testFollowsSelection() throws Throwable {
144
		// selection before selection changes
145
		TestPropertySheetPage firstPage = (TestPropertySheetPage) propertySheet
146
				.getCurrentPage();
147
		Object firstSelection = firstPage.getSelection();
148
		assertNotNull(firstSelection);
149
150
		// change the selection explicitly
151
		selectionProviderView.setSelection(new Object());
152
		TestPropertySheetPage secondPage = (TestPropertySheetPage) propertySheet
153
				.getCurrentPage();
154
155
		assertNotSame("PropertySheet hasn't changed selection", firstSelection,
156
				secondPage.getSelection());
157
	}
158
159
	// make sure the property sheet follows selection/part changes
160
	public void testFollowsParts() throws Throwable {
161
		// selection before selection changes
162
		TestPropertySheetPage firstPage = (TestPropertySheetPage) propertySheet
163
				.getCurrentPage();
164
		Object firstPart = firstPage.getPart();
165
		assertNotNull(firstPart);
166
167
		// change the part explicitly (reusing the NonRestorableView here)
168
		TestPropertySheetPage testPropertySheetPage2 = new TestPropertySheetPage();
169
		Platform.getAdapterManager().registerAdapters(testPropertySheetPage2,
170
				org.eclipse.ui.tests.session.NonRestorableView.class);
171
		activePage.showView(NonRestorableView.ID);
172
173
		TestPropertySheetPage secondPage = (TestPropertySheetPage) propertySheet
174
				.getCurrentPage();
175
176
		assertEquals(testPropertySheetPage2, secondPage);
177
		assertNotSame("PropertySheet hasn't changed selection", firstPart,
178
				secondPage.getSelection());
179
	}
180
181
	public void testPinning() throws Throwable {
182
183
		// execute the pin action on the property sheet
184
		IAction action = getPropertySheetAction(propertySheet,
185
				PIN_PROPERTY_SHEET_ACTION_ID_PREFIX);
186
		action.setChecked(true);
187
188
		// get the content of the pinned property sheet for later comparison
189
		TestPropertySheetPage firstPage = (TestPropertySheetPage) propertySheet
190
				.getCurrentPage();
191
		assertNotNull(firstPage);
192
		Object firstSelection = firstPage.getSelection();
193
		assertNotNull(firstSelection);
194
		IWorkbenchPart firstPart = firstPage.getPart();
195
		assertNotNull(firstPart);
196
197
		// change the selection/part
198
		selectionProviderView.setSelection(new Object());
199
		TestPropertySheetPage testPropertySheetPage2 = new TestPropertySheetPage();
200
		Platform.getAdapterManager().registerAdapters(testPropertySheetPage2,
201
				org.eclipse.ui.tests.session.NonRestorableView.class);
202
		activePage.showView(NonRestorableView.ID);
203
204
		TestPropertySheetPage secondPage = (TestPropertySheetPage) propertySheet
205
				.getCurrentPage();
206
		assertEquals("PropertySheet has changed page", firstPage, secondPage);
207
		assertEquals("PropertySheetPage has changed selection", firstSelection,
208
				secondPage.getSelection());
209
		assertEquals("PropertySheetPage has changed part", firstPart,
210
				secondPage.getPart());
211
	}
212
213
	public void testUnpinningWhenPinnedPartIsClosed() throws Throwable {
214
		// execute the pin action on the property sheet
215
		IAction action = getPropertySheetAction(propertySheet,
216
				PIN_PROPERTY_SHEET_ACTION_ID_PREFIX);
217
		action.setChecked(true);
218
219
		// close the part the property sheet is pinned to
220
		activePage.hideView(selectionProviderView);
221
222
		// the action and therefore the property sheet should be unpinned
223
		assertFalse(action.isChecked());
224
	}
225
226
	public void testNewPropertySheet() {
227
	fail("Not yet implemented");
228
	}
229
}

Return to bug 248103