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

(-)Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyDialog.java (-73 / +83 lines)
Lines 13-18 Link Here
13
import java.util.Iterator;
13
import java.util.Iterator;
14
14
15
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.core.runtime.Platform;
16
import org.eclipse.jface.dialogs.MessageDialog;
17
import org.eclipse.jface.dialogs.MessageDialog;
17
import org.eclipse.jface.preference.PreferenceManager;
18
import org.eclipse.jface.preference.PreferenceManager;
18
import org.eclipse.jface.viewers.ISelection;
19
import org.eclipse.jface.viewers.ISelection;
Lines 30-54 Link Here
30
 * type.
31
 * type.
31
 */
32
 */
32
public class PropertyDialog extends FilteredPreferenceDialog {
33
public class PropertyDialog extends FilteredPreferenceDialog {
33
    private ISelection selection;
34
	private ISelection selection;
34
35
35
    //The id of the last page that was selected
36
	// The id of the last page that was selected
36
    private static String lastPropertyId = null;
37
	private static String lastPropertyId = null;
37
38
38
    
39
	/**
39
    /**
40
	 * Create a new property dialog.
40
     * Create a new property dialog.
41
	 * 
41
     * 
42
	 * @param shell
42
     * @param shell the parent shell
43
	 *            the parent shell
43
     * @param propertyPageId the property page id
44
	 * @param propertyPageId
44
     * @param element the adaptable element
45
	 *            the property page id
45
     * @return the property dialog
46
	 * @param element
46
     */
47
	 *            the adaptable element
47
    public static PropertyDialog createDialogOn(Shell shell,final String propertyPageId, IAdaptable element){
48
	 * @return the property dialog
49
	 */
50
	public static PropertyDialog createDialogOn(Shell shell,
51
			final String propertyPageId, Object element) {
48
52
49
		PropertyPageManager pageManager = new PropertyPageManager();
53
		PropertyPageManager pageManager = new PropertyPageManager();
50
		String title = "";//$NON-NLS-1$
54
		String title = "";//$NON-NLS-1$
51
		
55
52
		if (element == null)
56
		if (element == null)
53
			return null;
57
			return null;
54
		// load pages for the selection
58
		// load pages for the selection
Lines 60-73 Link Here
60
				.iterator();
64
				.iterator();
61
		String name = getName(element);
65
		String name = getName(element);
62
		if (!pages.hasNext()) {
66
		if (!pages.hasNext()) {
63
			MessageDialog
67
			MessageDialog.openInformation(shell,
64
					.openInformation(
68
					WorkbenchMessages.PropertyDialog_messageTitle, NLS.bind(
65
							shell,
69
							WorkbenchMessages.PropertyDialog_noPropertyMessage,
66
							WorkbenchMessages.PropertyDialog_messageTitle,
70
							name));
67
							NLS.bind(WorkbenchMessages.PropertyDialog_noPropertyMessage,  name)); 
68
			return null;
71
			return null;
69
		}
72
		}
70
		title = NLS.bind(WorkbenchMessages.PropertyDialog_propertyMessage,  name ); 
73
		title = NLS
74
				.bind(WorkbenchMessages.PropertyDialog_propertyMessage, name);
71
		PropertyDialog propertyDialog = new PropertyDialog(shell, pageManager,
75
		PropertyDialog propertyDialog = new PropertyDialog(shell, pageManager,
72
				new StructuredSelection(element));
76
				new StructuredSelection(element));
73
77
Lines 81-148 Link Here
81
				IWorkbenchHelpContextIds.PROPERTY_DIALOG);
85
				IWorkbenchHelpContextIds.PROPERTY_DIALOG);
82
86
83
		return propertyDialog;
87
		return propertyDialog;
84
	
88
85
    }
89
	}
86
    
90
87
    /**
91
	/**
88
	 * Returns the name of the given element.
92
	 * Returns the name of the given element.
89
	 * 
93
	 * 
90
	 * @param element
94
	 * @param element
91
	 *            the element
95
	 *            the element
92
	 * @return the name of the element
96
	 * @return the name of the element
93
	 */
97
	 */
94
	private static String getName(IAdaptable element) {
98
	private static String getName(Object element) {
95
		IWorkbenchAdapter adapter = (IWorkbenchAdapter) element
99
		IWorkbenchAdapter adapter = null;
96
				.getAdapter(IWorkbenchAdapter.class);
100
		if (element instanceof IAdaptable) {
97
		if (adapter != null) 
101
			adapter = (IWorkbenchAdapter) ((IAdaptable) element)
102
					.getAdapter(IWorkbenchAdapter.class);
103
		} else {
104
			adapter = (IWorkbenchAdapter) Platform.getAdapterManager()
105
					.getAdapter(element, IWorkbenchAdapter.class);
106
		}
107
		if (adapter != null)
98
			return adapter.getLabel(element);
108
			return adapter.getLabel(element);
99
		return "";//$NON-NLS-1$
109
		return "";//$NON-NLS-1$
100
	}
110
	}
101
	
102
    /**
103
     * Create an instance of the receiver.
104
     * @param parentShell
105
     * @param mng
106
     * @param selection
107
     */
108
    public PropertyDialog(Shell parentShell, PreferenceManager mng,
109
            ISelection selection) {
110
        super(parentShell, mng);
111
        setSelection(selection);
112
    }
113
114
    /**
115
     * Returns selection in the "Properties" action context.
116
     * 
117
     * @return the selection
118
     */
119
    public ISelection getSelection() {
120
        return selection;
121
    }
122
123
    /**
124
     * Sets the selection that will be used to determine target object.
125
     * 
126
     * @param newSelection the new selection
127
     */
128
    public void setSelection(ISelection newSelection) {
129
        selection = newSelection;
130
    }
131
132
    /**
133
     * Get the name of the selected item preference
134
     */
135
    protected String getSelectedNodePreference() {
136
        return lastPropertyId;
137
    }
138
139
    /**
140
     * Get the name of the selected item preference
141
     */
142
    protected void setSelectedNodePreference(String pageId) {
143
        lastPropertyId = pageId;
144
    }
145
    
146
111
112
	/**
113
	 * Create an instance of the receiver.
114
	 * 
115
	 * @param parentShell
116
	 * @param mng
117
	 * @param selection
118
	 */
119
	public PropertyDialog(Shell parentShell, PreferenceManager mng,
120
			ISelection selection) {
121
		super(parentShell, mng);
122
		setSelection(selection);
123
	}
124
125
	/**
126
	 * Returns selection in the "Properties" action context.
127
	 * 
128
	 * @return the selection
129
	 */
130
	public ISelection getSelection() {
131
		return selection;
132
	}
133
134
	/**
135
	 * Sets the selection that will be used to determine target object.
136
	 * 
137
	 * @param newSelection
138
	 *            the new selection
139
	 */
140
	public void setSelection(ISelection newSelection) {
141
		selection = newSelection;
142
	}
143
144
	/**
145
	 * Get the name of the selected item preference
146
	 */
147
	protected String getSelectedNodePreference() {
148
		return lastPropertyId;
149
	}
150
151
	/**
152
	 * Get the name of the selected item preference
153
	 */
154
	protected void setSelectedNodePreference(String pageId) {
155
		lastPropertyId = pageId;
156
	}
147
157
148
}
158
}
(-)Eclipse UI/org/eclipse/ui/internal/dialogs/IPropertyPageContributor.java (-3 / +4 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.dialogs;
11
package org.eclipse.ui.internal.dialogs;
12
12
13
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.ui.internal.IObjectContributor;
13
import org.eclipse.ui.internal.IObjectContributor;
15
14
16
/**
15
/**
Lines 23-31 Link Here
23
    /**
22
    /**
24
     * Implement this method to add instances of PropertyPage class to the
23
     * Implement this method to add instances of PropertyPage class to the
25
     * property page manager.
24
     * property page manager.
25
     * @param manager the contributor manager onto which to contribute the
26
     * property pages.
27
     * @param object the type for which pages should be contributed. 
26
     * @return true if pages were added, false if not.
28
     * @return true if pages were added, false if not.
27
     */
29
     */
28
29
    public boolean contributePropertyPages(PropertyPageManager manager,
30
    public boolean contributePropertyPages(PropertyPageManager manager,
30
            IAdaptable object);
31
            Object object);
31
}
32
}
(-)Eclipse UI/org/eclipse/ui/internal/dialogs/RegistryPageContributor.java (-7 / +9 lines)
Lines 67-78 Link Here
67
        adaptable = Boolean.valueOf(pageElement.getAttribute(PropertyPagesRegistryReader.ATT_ADAPTABLE)).booleanValue();
67
        adaptable = Boolean.valueOf(pageElement.getAttribute(PropertyPagesRegistryReader.ATT_ADAPTABLE)).booleanValue();
68
    }
68
    }
69
69
70
	/**
70
	 /* (non-Javadoc)
71
     * Implements the interface by creating property page specified with
71
     * @see org.eclipse.ui.internal.dialogs.IPropertyPageContributor#contributePropertyPages(org.eclipse.ui.internal.dialogs.PropertyPageManager, java.lang.Object)
72
     * the configuration element.
73
     */
72
     */
74
    public boolean contributePropertyPages(PropertyPageManager mng,
73
    public boolean contributePropertyPages(PropertyPageManager mng,
75
            IAdaptable element) {
74
            Object element) {
76
        PropertyPageNode node = new PropertyPageNode(this, element);
75
        PropertyPageNode node = new PropertyPageNode(this, element);
77
        
76
        
78
        if(getCategory() == null){
77
        if(getCategory() == null){
Lines 92-98 Link Here
92
     * @return the property page
91
     * @return the property page
93
     * @throws CoreException thrown if there is a problem creating the apge
92
     * @throws CoreException thrown if there is a problem creating the apge
94
     */
93
     */
95
    public IWorkbenchPropertyPage createPage(IAdaptable element)
94
    public IWorkbenchPropertyPage createPage(Object element)
96
            throws CoreException {
95
            throws CoreException {
97
        IWorkbenchPropertyPage ppage = null;
96
        IWorkbenchPropertyPage ppage = null;
98
        ppage = (IWorkbenchPropertyPage) WorkbenchPlugin.createExtension(
97
        ppage = (IWorkbenchPropertyPage) WorkbenchPlugin.createExtension(
Lines 111-117 Link Here
111
           }
110
           }
112
        }
111
        }
113
        
112
        
114
        ppage.setElement((IAdaptable)adapted);
113
        if(adapted instanceof IAdaptable)
114
        	ppage.setElement((IAdaptable) adapted);
115
        else
116
        	ppage.setElement(new AdaptableForwarder(adapted));
115
117
116
        return ppage;
118
        return ppage;
117
    }
119
    }
Lines 126-132 Link Here
126
        if (iconName == null)
128
        if (iconName == null)
127
            return null;
129
            return null;
128
        return AbstractUIPlugin.imageDescriptorFromPlugin(pageElement
130
        return AbstractUIPlugin.imageDescriptorFromPlugin(pageElement
129
                .getNamespace(), iconName);
131
                .getNamespaceIdentifier(), iconName);
130
    }
132
    }
131
133
132
    /**
134
    /**
(-)Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyPageContributorManager.java (-10 / +4 lines)
Lines 18-24 Link Here
18
import java.util.Iterator;
18
import java.util.Iterator;
19
import java.util.List;
19
import java.util.List;
20
20
21
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.core.runtime.IConfigurationElement;
21
import org.eclipse.core.runtime.IConfigurationElement;
23
import org.eclipse.core.runtime.IExtension;
22
import org.eclipse.core.runtime.IExtension;
24
import org.eclipse.core.runtime.Platform;
23
import org.eclipse.core.runtime.Platform;
Lines 115-124 Link Here
115
	 * contributors and sequentially invoke them to contribute to the property
114
	 * contributors and sequentially invoke them to contribute to the property
116
	 * page manager. Matching algorithm will also check subclasses and
115
	 * page manager. Matching algorithm will also check subclasses and
117
	 * implemented interfaces.
116
	 * implemented interfaces.
118
	 * 
117
	 * @param manager
118
	 * @param object
119
	 * @return true if contribution took place, false otherwise.
119
	 * @return true if contribution took place, false otherwise.
120
	 */
120
	 */
121
	public boolean contribute(PropertyPageManager manager, IAdaptable object) {
121
	public boolean contribute(PropertyPageManager manager, Object object) {
122
122
123
		List result = getContributors(object);
123
		List result = getContributors(object);
124
124
Lines 176-181 Link Here
176
	/**
176
	/**
177
	 * Ideally, shared instance should not be used and manager should be located
177
	 * Ideally, shared instance should not be used and manager should be located
178
	 * in the workbench class.
178
	 * in the workbench class.
179
	 * @return PropertyPageContributorManager
179
	 */
180
	 */
180
	public static PropertyPageContributorManager getManager() {
181
	public static PropertyPageContributorManager getManager() {
181
		if (sharedInstance == null)
182
		if (sharedInstance == null)
Lines 184-196 Link Here
184
	}
185
	}
185
186
186
	/**
187
	/**
187
	 * Returns true if contributors exist in the manager for this object.
188
	 */
189
	public boolean hasContributorsFor(Object object) {
190
		return super.hasContributorsFor(object);
191
	}
192
193
	/**
194
	 * Loads property page contributors from the registry.
188
	 * Loads property page contributors from the registry.
195
	 */
189
	 */
196
	private void loadContributors() {
190
	private void loadContributors() {
(-)Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyPageNode.java (-3 / +2 lines)
Lines 11-17 Link Here
11
package org.eclipse.ui.internal.dialogs;
11
package org.eclipse.ui.internal.dialogs;
12
12
13
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.jface.dialogs.ErrorDialog;
14
import org.eclipse.jface.dialogs.ErrorDialog;
16
import org.eclipse.jface.resource.ImageDescriptor;
15
import org.eclipse.jface.resource.ImageDescriptor;
17
import org.eclipse.swt.graphics.Image;
16
import org.eclipse.swt.graphics.Image;
Lines 32-38 Link Here
32
31
33
    private Image icon;
32
    private Image icon;
34
33
35
    private IAdaptable element;
34
    private Object element;
36
35
37
    /**
36
    /**
38
     * Create a new instance of the receiver.
37
     * Create a new instance of the receiver.
Lines 40-46 Link Here
40
     * @param element
39
     * @param element
41
     */
40
     */
42
    public PropertyPageNode(RegistryPageContributor contributor,
41
    public PropertyPageNode(RegistryPageContributor contributor,
43
            IAdaptable element) {
42
            Object element) {
44
        super(contributor.getPageId(), contributor.getConfigurationElement());
43
        super(contributor.getPageId(), contributor.getConfigurationElement());
45
        this.contributor = contributor;
44
        this.contributor = contributor;
46
        this.element = element;
45
        this.element = element;
(-)Eclipse UI/org/eclipse/ui/dialogs/PropertyDialogAction.java (-5 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.dialogs;
11
package org.eclipse.ui.dialogs;
12
12
13
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.jface.preference.PreferenceDialog;
13
import org.eclipse.jface.preference.PreferenceDialog;
15
import org.eclipse.jface.util.Assert;
14
import org.eclipse.jface.util.Assert;
16
import org.eclipse.jface.viewers.ISelectionProvider;
15
import org.eclipse.jface.viewers.ISelectionProvider;
Lines 101-108 Link Here
101
	 * @return boolean
100
	 * @return boolean
102
	 */
101
	 */
103
	private boolean hasPropertyPagesFor(Object object) {
102
	private boolean hasPropertyPagesFor(Object object) {
104
		PropertyPageContributorManager manager = PropertyPageContributorManager.getManager();
103
		return PropertyPageContributorManager.getManager().hasContributorsFor(object);
105
		return manager.hasContributorsFor(object);
106
	}
104
	}
107
105
108
	/**
106
	/**
Lines 167-173 Link Here
167
	 */
165
	 */
168
	public PreferenceDialog createDialog() {
166
	public PreferenceDialog createDialog() {
169
167
170
		IAdaptable element = (IAdaptable) getStructuredSelection().getFirstElement();
168
		Object element = getStructuredSelection().getFirstElement();
171
		if (element == null)
169
		if (element == null)
172
			return null;
170
			return null;
173
		return PropertyDialog
171
		return PropertyDialog
(-)Eclipse UI/org/eclipse/ui/IWorkbenchPropertyPage.java (-1 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 12-17 Link Here
12
12
13
import org.eclipse.core.runtime.IAdaptable;
13
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.jface.preference.IPreferencePage;
14
import org.eclipse.jface.preference.IPreferencePage;
15
import org.eclipse.ui.dialogs.PropertyDialogAction;
15
16
16
/**
17
/**
17
 * Interface for workbench property pages. Property pages generally show up in
18
 * Interface for workbench property pages. Property pages generally show up in
Lines 43-48 Link Here
43
     * Sets the object that owns the properties shown in this page.
44
     * Sets the object that owns the properties shown in this page.
44
     * The page is expected to store this object and provide it if
45
     * The page is expected to store this object and provide it if
45
     * <code>getElement</code> is called.
46
     * <code>getElement</code> is called.
47
     * <p> As of Eclipse 3.2 the org.eclipse.ui.propertyPages extension
48
     * point now supports non IAdaptable inputs. An input
49
     * that is not an IAdaptable will be wrapped in an 
50
     * IAdaptable by the workbench before it is forwarded 
51
     * to this method.
52
     * </p>
53
     * @see PropertyDialogAction
46
     *
54
     *
47
     * @param element the object that owns the properties shown in this page
55
     * @param element the object that owns the properties shown in this page
48
     */
56
     */
(-)Eclipse (+46 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.dialogs;
12
13
import org.eclipse.core.runtime.IAdaptable;
14
15
/**
16
 * Class that wraps an object and forwards adapter calls if possible, otherwise
17
 * returns the object. This is used to maintain API compatibility with methods that
18
 * need an IAdaptable but when the operation supports a broader type.
19
 * 
20
 * @since 3.2
21
 */
22
public class AdaptableForwarder implements IAdaptable {
23
24
	private Object element;
25
	
26
	/**
27
	 * Create a new instance of the receiver.
28
	 * @param element
29
	 */
30
	public AdaptableForwarder(Object element) {
31
		this.element = element;
32
	}
33
	
34
	/* (non-Javadoc)
35
	 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
36
	 */
37
	public Object getAdapter(Class adapter) {
38
		if(adapter.isInstance(element)) {
39
			return element;
40
		}
41
		if(element instanceof IAdaptable) {
42
			return ((IAdaptable)element).getAdapter(adapter);
43
		}
44
		return null;
45
	}
46
}

Return to bug 92601