Skip to main content
summaryrefslogtreecommitdiffstats
blob: 37f144056c879c6224792f4b92a256e59ade841c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/********************************************************************************
 * Copyright (c) 2002, 2006 IBM Corporation. All rights reserved.
 * This program and the accompanying materials are made available under the terms
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is 
 * available at http://www.eclipse.org/legal/epl-v10.html
 * 
 * Initial Contributors:
 * The following IBM employees contributed to the Remote System Explorer
 * component that contains this file: David McKnight, Kushal Munir, 
 * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, 
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
 * 
 * Contributors:
 * {Name} (company) - description of contribution.
 ********************************************************************************/

package org.eclipse.rse.ui.actions;
import java.text.MessageFormat;
import java.util.Iterator;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.rse.core.SystemPropertyPageExtensionManager;
import org.eclipse.rse.ui.GenericMessages;
import org.eclipse.rse.ui.ISystemContextMenuConstants;
import org.eclipse.rse.ui.SystemResources;
import org.eclipse.rse.ui.view.ISystemRemoteElementAdapter;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.dialogs.PropertyDialog;
import org.eclipse.ui.internal.dialogs.PropertyPageManager;


/**
 * The action shows properties for remote objects
 */
public class SystemRemotePropertiesAction 
       extends SystemBaseAction 
       
{
		
	/**
	 * Constructor
	 */
	public SystemRemotePropertiesAction(Shell shell) 
	{
		super(SystemResources.ACTION_REMOTE_PROPERTIES_LABEL, SystemResources.ACTION_REMOTE_PROPERTIES_TOOLTIP,shell);
        allowOnMultipleSelection(false);
		setContextMenuGroup(ISystemContextMenuConstants.GROUP_PROPERTIES);        
	}

	/**
	 * We override from parent to do unique checking...
	 * <p>
	 * It is too expense to check for registered property pages at popup time, so we just return true.
	 * <p>
	 * @see SystemBaseAction#updateSelection(IStructuredSelection)
	 */
	public boolean updateSelection(IStructuredSelection selection)
	{
		boolean enable = true;
		return enable;
	}
	
	/**
	 * Returns the name of the given element.
	 * @param element the element
	 * @return the name of the element
	 */
	private String getName(Object element) 
	{
		return getAdapter(element).getName(element);
	}
	/**
	 * Returns whether the provided object has pages registered in the property page
	 * manager.
	 */
	public boolean hasPropertyPagesFor(Object object) 
	{
		//PropertyPageContributorManager manager = PropertyPageContributorManager.getManager();
		return getOurPropertyPageManager().hasContributorsFor(getRemoteAdapter(object), object);
	}
	/**
	 * Get the remote property page extension manager
	 */
	private SystemPropertyPageExtensionManager getOurPropertyPageManager()
	{
		return SystemPropertyPageExtensionManager.getManager();
	}
	/**
	 * Returns whether this action is actually applicable to the current selection.
	 * Returns true if there are any registered property pages applicable for the
	 * given input object.
	 * <p>
	 * This method is generally too expensive to use when updating the enabled state
	 * of the action.
	 * </p>
	 *
	 * @return <code>true</code> if there are property pages for the currently
	 *   selected element, and <code>false</code> otherwise
	 */
	public boolean isApplicableForSelection() 
	{
		return hasPropertyPagesFor(getFirstSelection());
	}
	/**
	 * The <code>PropertyDialogAction</code> implementation of this 
	 * <code>IAction</code> method performs the action by opening the Property Page
	 * Dialog for the current selection. If no pages are found, an informative 
	 * message dialog is presented instead.
	 */
	public void run() 
	{		
		PropertyPageManager pageManager = new PropertyPageManager();
		String title = "";//$NON-NLS-1$	

		// get selection
		//Object element = getFirstSelection();
		IAdaptable element = (IAdaptable)getFirstSelection();
		if (element == null)
		  return;
		ISystemRemoteElementAdapter adapter = getRemoteAdapter(element);			
		if (adapter == null)
		  return;

		// load pages for the selection
		// fill the manager with contributions from the matching contributors
		getOurPropertyPageManager().contribute(pageManager, getRemoteAdapter(element), element);
		//PropertyPageContributorManager.getManager().contribute(pageManager, element);		
	
	    Shell shell = getShell();
	    
		// testing if there are pages in the manager
		Iterator pages = pageManager.getElements(PreferenceManager.PRE_ORDER).iterator();
		String name = getName(element);
		if (!pages.hasNext()) {
			MessageDialog.openInformation(
				shell,
				GenericMessages.PropertyDialog_messageTitle, 
				MessageFormat.format(GenericMessages.PropertyDialog_noPropertyMessage, new Object[] {name})); 
			return;
		} 
		else
		{	
			title = MessageFormat.format(GenericMessages.PropertyDialog_propertyMessage, new Object[] {name});
		}

		PropertyDialog propertyDialog = new PropertyDialog(shell, pageManager, getSelection()); 
		propertyDialog.create();
		propertyDialog.getShell().setText(title);
		
		
		
		// TODO - hack to make this work in  3.1
		String id = PlatformUI.PLUGIN_ID + ".property_dialog_context";
		PlatformUI.getWorkbench().getHelpSystem().setHelp(propertyDialog.getShell(), id);
		
		propertyDialog.open();
	}
}

Back to the top