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

Collapse All | Expand All

(-)schema/navigatorContent.exsd (+32 lines)
Lines 38-43 Link Here
38
               <element ref="actionProvider" minOccurs="0" maxOccurs="unbounded"/>
38
               <element ref="actionProvider" minOccurs="0" maxOccurs="unbounded"/>
39
               <element ref="commonWizard" minOccurs="0" maxOccurs="unbounded"/>
39
               <element ref="commonWizard" minOccurs="0" maxOccurs="unbounded"/>
40
               <element ref="commonFilter" minOccurs="0" maxOccurs="unbounded"/>
40
               <element ref="commonFilter" minOccurs="0" maxOccurs="unbounded"/>
41
               <element ref="commandMenuContribution" minOccurs="0" maxOccurs="unbounded"/>
41
            </choice>
42
            </choice>
42
         </sequence>
43
         </sequence>
43
         <attribute name="point" type="string" use="required">
44
         <attribute name="point" type="string" use="required">
Lines 664-669 Link Here
664
      </complexType>
665
      </complexType>
665
   </element>
666
   </element>
666
667
668
   <element name="commandMenuContribution">
669
      <annotation>
670
         <documentation>
671
            Specifies the contribution of a command to the context menu associated with a Common Navigator ViewPart. This is used in conjuction with the &lt;b&gt;viewerCommandMenuBinding&lt;/b&gt; element in the &lt;b&gt;viewer&lt;/b&gt; extension point.
672
&lt;br/&gt;&lt;br/&gt;
673
Its function is similar the &lt;b&gt;menuContribution&lt;/b&gt; element in the &lt;b&gt;org.eclipse.ui.menus&lt;/b&gt; extention point (and replaces its use in the context of the Common Navigator).
674
&lt;br/&gt;&lt;br/&gt;
675
You should use this element (instead of the &lt;b&gt;menuContribution&lt;/b&gt; element) when there is a possibility that the same command may be associated with a given Common Navigator ViewPart instance. Configuring using this element will make sure the command only occurs one time in the context menu, where if you used the &lt;b&gt;menuContribution&lt;/b&gt; element the command would be duplicated.
676
         </documentation>
677
      </annotation>
678
      <complexType>
679
         <attribute name="commandId" type="string" use="required">
680
            <annotation>
681
               <documentation>
682
                  
683
               </documentation>
684
               <appInfo>
685
                  <meta.attribute kind="identifier" basedOn="org.eclipse.ui.commands/command/@id"/>
686
               </appInfo>
687
            </annotation>
688
         </attribute>
689
         <attribute name="after" type="string">
690
            <annotation>
691
               <documentation>
692
                  
693
               </documentation>
694
            </annotation>
695
         </attribute>
696
      </complexType>
697
   </element>
698
667
   <annotation>
699
   <annotation>
668
      <appInfo>
700
      <appInfo>
669
         <meta.section type="since"/>
701
         <meta.section type="since"/>
(-)schema/viewer.exsd (+114 lines)
Lines 33-38 Link Here
33
         <sequence>
33
         <sequence>
34
            <element ref="viewer" minOccurs="0" maxOccurs="unbounded"/>
34
            <element ref="viewer" minOccurs="0" maxOccurs="unbounded"/>
35
            <element ref="viewerContentBinding" minOccurs="0" maxOccurs="unbounded"/>
35
            <element ref="viewerContentBinding" minOccurs="0" maxOccurs="unbounded"/>
36
            <element ref="viewerCommandMenuBinding" minOccurs="0" maxOccurs="unbounded"/>
37
            <element ref="viewerHandlerBinding" minOccurs="0" maxOccurs="unbounded"/>
36
            <element ref="viewerActionBinding" minOccurs="0" maxOccurs="unbounded"/>
38
            <element ref="viewerActionBinding" minOccurs="0" maxOccurs="unbounded"/>
37
            <element ref="dragAssistant" minOccurs="0" maxOccurs="unbounded"/>
39
            <element ref="dragAssistant" minOccurs="0" maxOccurs="unbounded"/>
38
         </sequence>
40
         </sequence>
Lines 161-166 Link Here
161
      </complexType>
163
      </complexType>
162
   </element>
164
   </element>
163
165
166
   <element name="viewerCommandMenuBinding">
167
      <annotation>
168
         <documentation>
169
            Clients may use this to bind commands and handlers to their viewer. Although you can bind commands to a view using the normal mechanisms in the LINKcommand service, using this element is recommended if there will be multple unrelated plugins contributing to the view as it provides two additional benefits:
170
&lt;ol&gt;
171
&lt;li&gt;Prevents duplication - in the event that the same command is found to a viewer multiple times (by multiple unrelated plugins), it will be found only once. As is normal when using handlers, they must properly coordinate their activation.
172
&lt;li&gt;Dynamic handler creation - the specified handler will be created in response to this element, and if it has a constructor that has a LINKViewPart as its argument, that will be invoked, allowing the handler to register for and respond to the view&apos;s selection events.
173
&lt;/ol&gt;
174
Clients may define an &lt;b&gt;includes&lt;/b&gt; element to select which commands are visible to the viewer, and  similarly an &lt;b&gt;excludes&lt;/b&gt; element for commands that should not be made visible to the viewer. 
175
&lt;br&gt;&lt;br&gt;
176
A viewer may have multiple &lt;b&gt;viewerCommandBinding&lt;/b&gt;s defined, and their &lt;b&gt;includes&lt;/b&gt;/&lt;b&gt;excludes&lt;/b&gt; statements will be aggregated to produce the final behavior.
177
&lt;br&gt;&lt;br&gt;
178
For &lt;b&gt;actionProvider&lt;/b&gt; definitions which are not nested under a &lt;b&gt;navigatorContent&lt;/b&gt; definition, clients may specify a custom id. If clients do not specify an id, the id defaults to &quot;org.eclipse.ui.navigator.actionProvider.X&quot;. For clients that wish to pick up &lt;b&gt;actionProvider&lt;/b&gt;s with no specific id, clients must define a &lt;b&gt;viewerActionBinding&lt;/b&gt; for the default id. See the examples section for how this is done.
179
         </documentation>
180
      </annotation>
181
      <complexType>
182
         <sequence>
183
            <element ref="includes" minOccurs="0" maxOccurs="1"/>
184
            <element ref="excludes" minOccurs="0" maxOccurs="1"/>
185
         </sequence>
186
         <attribute name="viewerId" type="string" use="required">
187
            <annotation>
188
               <documentation>
189
                  The id of the common viewer. If the viewer is in a common navigator then the id must match the navigator&apos;s id defined in its &lt;b&gt;org.eclipse.ui.views&lt;/b&gt; extension.
190
               </documentation>
191
            </annotation>
192
         </attribute>
193
      </complexType>
194
   </element>
195
196
   <element name="viewerHandlerBinding">
197
      <annotation>
198
         <documentation>
199
            *** get rid of this one, just start the handlers with the project explorer **
200
201
Clients may use this to bind commands and handlers to their viewer. Although you can bind commands to a view using the normal mechanisms in the LINKcommand service, using this element is recommended if there will be multple unrelated plugins contributing to the view as it provides two additional benefits:
202
&lt;ol&gt;
203
&lt;li&gt;Prevents duplication - in the event that the same command is found to a viewer multiple times (by multiple unrelated plugins), it will be found only once. As is normal when using handlers, they must properly coordinate their activation.
204
&lt;li&gt;Dynamic handler creation - the specified handler will be created in response to this element, and if it has a constructor that has a LINKViewPart as its argument, that will be invoked, allowing the handler to register for and respond to the view&apos;s selection events.
205
&lt;/ol&gt;
206
Clients may define an &lt;b&gt;includes&lt;/b&gt; element to select which commands are visible to the viewer, and  similarly an &lt;b&gt;excludes&lt;/b&gt; element for commands that should not be made visible to the viewer. 
207
&lt;br&gt;&lt;br&gt;
208
A viewer may have multiple &lt;b&gt;viewerCommandBinding&lt;/b&gt;s defined, and their &lt;b&gt;includes&lt;/b&gt;/&lt;b&gt;excludes&lt;/b&gt; statements will be aggregated to produce the final behavior.
209
&lt;br&gt;&lt;br&gt;
210
For &lt;b&gt;actionProvider&lt;/b&gt; definitions which are not nested under a &lt;b&gt;navigatorContent&lt;/b&gt; definition, clients may specify a custom id. If clients do not specify an id, the id defaults to &quot;org.eclipse.ui.navigator.actionProvider.X&quot;. For clients that wish to pick up &lt;b&gt;actionProvider&lt;/b&gt;s with no specific id, clients must define a &lt;b&gt;viewerActionBinding&lt;/b&gt; for the default id. See the examples section for how this is done.
211
         </documentation>
212
      </annotation>
213
      <complexType>
214
         <sequence>
215
            <element ref="includes" minOccurs="0" maxOccurs="1"/>
216
            <element ref="excludes" minOccurs="0" maxOccurs="1"/>
217
         </sequence>
218
         <attribute name="viewerId" type="string" use="required">
219
            <annotation>
220
               <documentation>
221
                  The id of the common viewer. If the viewer is in a common navigator then the id must match the navigator&apos;s id defined in its &lt;b&gt;org.eclipse.ui.views&lt;/b&gt; extension.
222
               </documentation>
223
            </annotation>
224
         </attribute>
225
      </complexType>
226
   </element>
227
164
   <element name="includes">
228
   <element name="includes">
165
      <annotation>
229
      <annotation>
166
         <documentation>
230
         <documentation>
Lines 178-183 Link Here
178
            <sequence>
242
            <sequence>
179
               <element ref="actionExtension" minOccurs="1" maxOccurs="unbounded"/>
243
               <element ref="actionExtension" minOccurs="1" maxOccurs="unbounded"/>
180
            </sequence>
244
            </sequence>
245
            <sequence>
246
               <element ref="commandMenuExtension" minOccurs="1" maxOccurs="unbounded"/>
247
            </sequence>
248
            <sequence>
249
               <element ref="handler" minOccurs="1" maxOccurs="unbounded"/>
250
            </sequence>
181
         </choice>
251
         </choice>
182
      </complexType>
252
      </complexType>
183
   </element>
253
   </element>
Lines 200-205 Link Here
200
            <sequence>
270
            <sequence>
201
               <element ref="actionExtension" minOccurs="1" maxOccurs="unbounded"/>
271
               <element ref="actionExtension" minOccurs="1" maxOccurs="unbounded"/>
202
            </sequence>
272
            </sequence>
273
            <sequence>
274
               <element ref="commandMenuExtension" minOccurs="1" maxOccurs="unbounded"/>
275
            </sequence>
276
            <sequence>
277
               <element ref="handler" minOccurs="1" maxOccurs="unbounded"/>
278
            </sequence>
203
         </choice>
279
         </choice>
204
      </complexType>
280
      </complexType>
205
   </element>
281
   </element>
Lines 425-430 Link Here
425
      </complexType>
501
      </complexType>
426
   </element>
502
   </element>
427
503
504
   <element name="commandMenuExtension">
505
      <annotation>
506
         <documentation>
507
            Indicates the command id or regular expression pattern to be used to find the command(s) to be associated with the viewer. These must be declared using the &lt;b&gt;commandMenuContribution&lt;/b&gt; element in the &lt;b&gt;navigatorContent&lt;/b&gt; extension point.
508
         </documentation>
509
      </annotation>
510
      <complexType>
511
         <attribute name="pattern" type="string" use="required">
512
            <annotation>
513
               <documentation>
514
                  Content extensions may be selected exactly by using their content extension id. Clients may also use a regular expression pattern to select any content extensions that have ids that match the pattern. 
515
&lt;p&gt;
516
Patterns are regular expressions which match unique identifiers. Please see the Java(tm) Platform documentation for &lt;code&gt;java.util.regex.Pattern&lt;/code&gt; for further details.
517
               </documentation>
518
            </annotation>
519
         </attribute>
520
      </complexType>
521
   </element>
522
523
   <element name="handler">
524
      <annotation>
525
         <documentation>
526
            The identification of a handler to bind in the &lt;b&gt;viewerCommandBinding&lt;/b&gt;.
527
         </documentation>
528
      </annotation>
529
      <complexType>
530
         <attribute name="pattern" type="string" use="required">
531
            <annotation>
532
               <documentation>
533
                  Content extensions may be selected exactly by using their content extension id. Clients may also use a regular expression pattern to select any content extensions that have ids that match the pattern. 
534
&lt;p&gt;
535
Patterns are regular expressions which match unique identifiers. Please see the Java(tm) Platform documentation for &lt;code&gt;java.util.regex.Pattern&lt;/code&gt; for further details.
536
               </documentation>
537
            </annotation>
538
         </attribute>
539
      </complexType>
540
   </element>
541
428
   <annotation>
542
   <annotation>
429
      <appInfo>
543
      <appInfo>
430
         <meta.section type="since"/>
544
         <meta.section type="since"/>
(-)src/org/eclipse/ui/internal/navigator/NavigatorContentService.java (+49 lines)
Lines 43-49 Link Here
43
import org.eclipse.jface.viewers.Viewer;
43
import org.eclipse.jface.viewers.Viewer;
44
44
45
import org.eclipse.ui.IMemento;
45
import org.eclipse.ui.IMemento;
46
import org.eclipse.ui.PlatformUI;
46
import org.eclipse.ui.internal.navigator.dnd.NavigatorDnDService;
47
import org.eclipse.ui.internal.navigator.dnd.NavigatorDnDService;
48
import org.eclipse.ui.internal.navigator.extensions.CommandMenuContributionDescriptor;
49
import org.eclipse.ui.internal.navigator.extensions.CommandMenuContributionDescriptorManager;
47
import org.eclipse.ui.internal.navigator.extensions.ExtensionPriorityComparator;
50
import org.eclipse.ui.internal.navigator.extensions.ExtensionPriorityComparator;
48
import org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor;
51
import org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor;
49
import org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptorManager;
52
import org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptorManager;
Lines 52-57 Link Here
52
import org.eclipse.ui.internal.navigator.extensions.NavigatorViewerDescriptorManager;
55
import org.eclipse.ui.internal.navigator.extensions.NavigatorViewerDescriptorManager;
53
import org.eclipse.ui.internal.navigator.extensions.StructuredViewerManager;
56
import org.eclipse.ui.internal.navigator.extensions.StructuredViewerManager;
54
import org.eclipse.ui.internal.navigator.sorters.NavigatorSorterService;
57
import org.eclipse.ui.internal.navigator.sorters.NavigatorSorterService;
58
import org.eclipse.ui.menus.AbstractContributionFactory;
59
import org.eclipse.ui.menus.CommandContributionItem;
60
import org.eclipse.ui.menus.CommandContributionItemParameter;
61
import org.eclipse.ui.menus.IContributionRoot;
62
import org.eclipse.ui.menus.IMenuService;
55
import org.eclipse.ui.navigator.IDescriptionProvider;
63
import org.eclipse.ui.navigator.IDescriptionProvider;
56
import org.eclipse.ui.navigator.IExtensionActivationListener;
64
import org.eclipse.ui.navigator.IExtensionActivationListener;
57
import org.eclipse.ui.navigator.IExtensionStateModel;
65
import org.eclipse.ui.navigator.IExtensionStateModel;
Lines 67-72 Link Here
67
import org.eclipse.ui.navigator.INavigatorSaveablesService;
75
import org.eclipse.ui.navigator.INavigatorSaveablesService;
68
import org.eclipse.ui.navigator.INavigatorSorterService;
76
import org.eclipse.ui.navigator.INavigatorSorterService;
69
import org.eclipse.ui.navigator.INavigatorViewerDescriptor;
77
import org.eclipse.ui.navigator.INavigatorViewerDescriptor;
78
import org.eclipse.ui.services.IServiceLocator;
70
79
71
/**
80
/**
72
 * <p>
81
 * <p>
Lines 848-853 Link Here
848
		return result;
857
		return result;
849
	}
858
	}
850
859
860
	
861
	/**
862
	 * Install the commands into the specified viewer
863
	 * 
864
	 * @param viewer
865
	 */
866
	public void bindCommandMenuContributions(StructuredViewer viewer) {
867
		CommandMenuContributionDescriptorManager mgr = CommandMenuContributionDescriptorManager
868
				.getInstance();
869
870
		final IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService(
871
				IMenuService.class);
872
873
		String urlBase = "popup:" + getViewerId(); //$NON-NLS-1$
874
		
875
		Iterator it = mgr.getDescriptors().iterator();
876
		while (it.hasNext()) {
877
			CommandMenuContributionDescriptor desc = (CommandMenuContributionDescriptor) it.next();
878
			NavigatorViewerDescriptor vd = NavigatorViewerDescriptorManager.getInstance()
879
					.getNavigatorViewerDescriptor(getViewerId());
880
			if (vd.isVisibleCommand(desc.getCommandId())) {
881
				final CommandMenuContributionDescriptor finalDesc = desc;
882
883
				String url = urlBase;
884
				if (desc.getAfter() != null)
885
					url += "?after=" + desc.getAfter(); //$NON-NLS-1$
886
				
887
				AbstractContributionFactory factory = new AbstractContributionFactory(url, desc.getPluginId()) {
888
					public void createContributionItems(IServiceLocator serviceLocator,
889
							IContributionRoot additions) {
890
						CommandContributionItemParameter cp = new CommandContributionItemParameter(serviceLocator, null, finalDesc.getCommandId(), CommandContributionItem.STYLE_PULLDOWN);
891
						CommandContributionItem item = new CommandContributionItem(cp);
892
						additions.addContributionItem(item, null);
893
					}
894
				};
895
				menuService.addContributionFactory(factory);
896
			}
897
		}
898
	}
899
	
851
	/*
900
	/*
852
	 * (non-Javadoc)
901
	 * (non-Javadoc)
853
	 * 
902
	 * 
(-)src/org/eclipse/ui/internal/navigator/extensions/CommandMenuContributionDescriptor.java (+77 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2010 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.navigator.extensions;
12
13
import org.eclipse.core.runtime.Assert;
14
import org.eclipse.core.runtime.IConfigurationElement;
15
import org.eclipse.ui.internal.navigator.extensions.INavigatorContentExtPtConstants;
16
17
/**
18
 * 
19
 * 
20
 * @since 3.5
21
 */
22
public class CommandMenuContributionDescriptor implements INavigatorContentExtPtConstants {
23
24
	private final IConfigurationElement configurationElement;
25
26
	private final String commandId;
27
28
	private final String after;
29
30
	private final String pluginId;
31
32
	private String toString;
33
34
	/**
35
	 * @param aConfigElement
36
	 */
37
	public CommandMenuContributionDescriptor(IConfigurationElement aConfigElement) {
38
		super();
39
		Assert.isTrue(TAG_COMMAND_MENU_CONTRIBUTION.equals(aConfigElement.getName()));
40
		configurationElement = aConfigElement;
41
		pluginId = configurationElement.getContributor().getName();
42
		commandId = configurationElement.getAttribute(ATT_COMMAND_ID);
43
		after = configurationElement.getAttribute(ATT_AFTER);
44
	}
45
46
	/**
47
	 * 
48
	 * @return The command id.
49
	 */
50
	public String getCommandId() {
51
		return commandId;
52
	}
53
54
	/**
55
	 * 
56
	 * @return The after value which is which group the command is placed in in
57
	 *         the context menu.
58
	 */
59
	public String getAfter() {
60
		return after;
61
	}
62
63
	/**
64
	 * @return the id of the contributing plugin
65
	 */
66
	public String getPluginId() {
67
		return pluginId;
68
	}
69
70
	public String toString() {
71
		if (toString == null) {
72
			toString = "CommandMenuContributionDescriptor[commandId=" + getCommandId() + ", after=" + getAfter() + "]"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
73
		}
74
		return toString;
75
	}
76
77
}
(-)src/org/eclipse/ui/internal/navigator/extensions/CommandMenuContributionDescriptorManager.java (+79 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Oakland Software Incorporated 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
 *     Francis Upton IV, Oakland Software Incorporated - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.navigator.extensions;
12
13
import java.util.ArrayList;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Set;
17
18
import org.eclipse.core.runtime.IConfigurationElement;
19
import org.eclipse.ui.internal.navigator.extensions.NavigatorContentRegistryReader;
20
21
/**
22
 * Manages descriptors consumed from the 'commandMenuContribution' elements of
23
 * the <b>org.eclipse.ui.navigator.navigatorContent</b> extension point.
24
 * 
25
 * @since 3.5
26
 * 
27
 */
28
public class CommandMenuContributionDescriptorManager {
29
30
	private static final CommandMenuContributionDescriptorManager INSTANCE = new CommandMenuContributionDescriptorManager();
31
32
	private CommandMenuContributionDescriptorManager() {
33
34
		new RegistryReader().readRegistry();
35
	}
36
37
	/**
38
	 * @return the singleton instance of the this class
39
	 */
40
	public static CommandMenuContributionDescriptorManager getInstance() {
41
		return INSTANCE;
42
	}
43
44
	private final Set rootDescriptors = new HashSet();
45
46
	private final List rootDescriptorsList = new ArrayList();
47
48
	/**
49
	 * @return the descriptors
50
	 */
51
	public List getDescriptors() {
52
		return rootDescriptorsList;
53
	}
54
	
55
	/**
56
	 * 
57
	 * @param descriptor
58
	 *            A valid descriptor to begin managing.
59
	 */
60
	protected void addActionDescriptor(CommandMenuContributionDescriptor descriptor) {
61
		if (rootDescriptors.contains(descriptor.getCommandId())) {
62
			return;
63
		}
64
		rootDescriptorsList.add(descriptor);
65
		rootDescriptors.add(descriptor.getCommandId());
66
	}
67
68
	private class RegistryReader extends NavigatorContentRegistryReader {
69
70
		protected boolean readElement(IConfigurationElement anElement) {
71
			if (TAG_COMMAND_MENU_CONTRIBUTION.equals(anElement.getName())) {
72
				addActionDescriptor(new CommandMenuContributionDescriptor(anElement));
73
				return true;
74
			}
75
			return super.readElement(anElement);
76
		}
77
	}
78
79
}
(-)src/org/eclipse/ui/internal/navigator/extensions/INavigatorContentExtPtConstants.java (+9 lines)
Lines 20-25 Link Here
20
	String TAG_ACTION_PROVIDER = "actionProvider"; //$NON-NLS-1$
20
	String TAG_ACTION_PROVIDER = "actionProvider"; //$NON-NLS-1$
21
21
22
	/** */
22
	/** */
23
	String TAG_COMMAND_MENU_CONTRIBUTION = "commandMenuContribution"; //$NON-NLS-1$
24
25
	/** */
23
	String TAG_NAVIGATOR_CONTENT = "navigatorContent"; //$NON-NLS-1$
26
	String TAG_NAVIGATOR_CONTENT = "navigatorContent"; //$NON-NLS-1$
24
27
25
	/** */
28
	/** */
Lines 62-67 Link Here
62
	String ATT_ID = "id"; //$NON-NLS-1$
65
	String ATT_ID = "id"; //$NON-NLS-1$
63
66
64
	/** */
67
	/** */
68
	String ATT_COMMAND_ID = "commandId"; //$NON-NLS-1$
69
70
	/** */
71
	String ATT_AFTER = "after"; //$NON-NLS-1$
72
73
	/** */
65
	String ATT_NAME = "name"; //$NON-NLS-1$	 
74
	String ATT_NAME = "name"; //$NON-NLS-1$	 
66
75
67
	/** */
76
	/** */
(-)src/org/eclipse/ui/internal/navigator/extensions/IViewerExtPtConstants.java (+6 lines)
Lines 36-41 Link Here
36
	String TAG_VIEWER_ACTION_BINDING = "viewerActionBinding"; //$NON-NLS-1$
36
	String TAG_VIEWER_ACTION_BINDING = "viewerActionBinding"; //$NON-NLS-1$
37
37
38
	/** */
38
	/** */
39
	String TAG_VIEWER_COMMAND_BINDING = "viewerCommandMenuBinding"; //$NON-NLS-1$
40
41
	/** */
42
	String TAG_VIEWER_HANDLER_BINDING = "viewerHandlerBinding"; //$NON-NLS-1$
43
44
	/** */
39
	String TAG_POPUP_MENU = "popupMenu"; //$NON-NLS-1$ 
45
	String TAG_POPUP_MENU = "popupMenu"; //$NON-NLS-1$ 
40
46
41
	/** */
47
	/** */
(-)src/org/eclipse/ui/internal/navigator/extensions/NavigatorViewerDescriptor.java (-36 / +48 lines)
Lines 48-56 Link Here
48
48
49
	static final String ATT_PATTERN = "pattern"; //$NON-NLS-1$
49
	static final String ATT_PATTERN = "pattern"; //$NON-NLS-1$
50
50
51
	private static final String TAG_CONTENT_EXTENSION = "contentExtension"; //$NON-NLS-1$
51
	static final String TAG_CONTENT_EXTENSION = "contentExtension"; //$NON-NLS-1$
52
52
53
	private static final String TAG_ACTION_EXTENSION = "actionExtension"; //$NON-NLS-1$ 
53
	static final String TAG_ACTION_EXTENSION = "actionExtension"; //$NON-NLS-1$ 
54
55
	static final String TAG_COMMAND_MENU_EXTENSION = "commandMenuExtension"; //$NON-NLS-1$ 
54
56
55
	private final String viewerId;
57
	private final String viewerId;
56
58
Lines 60-65 Link Here
60
62
61
	private Binding contentBinding = new Binding(TAG_CONTENT_EXTENSION);
63
	private Binding contentBinding = new Binding(TAG_CONTENT_EXTENSION);
62
64
65
	private Binding commandBinding = new Binding(TAG_COMMAND_MENU_EXTENSION);
66
63
	private MenuInsertionPoint[] customInsertionPoints = null;
67
	private MenuInsertionPoint[] customInsertionPoints = null;
64
68
65
	private boolean allowsPlatformContributions = true;
69
	private boolean allowsPlatformContributions = true;
Lines 101-128 Link Here
101
		return popupMenuId != null ? popupMenuId : viewerId;
105
		return popupMenuId != null ? popupMenuId : viewerId;
102
	}
106
	}
103
107
104
	/**
105
	 * Consume an action binding for this viewer.
106
	 * 
107
	 * @param element
108
	 *            The IConfigurationElement containing a viewerActionBinding
109
	 *            element.
110
	 */
111
	public void consumeActionBinding(IConfigurationElement element) {
112
		consumeBinding(element, false);
113
	}
114
115
	/**
116
	 * Consume a content binding for this viewer.
117
	 * 
118
	 * @param element
119
	 *            The IConfigurationElement containing a viewerContentBinding
120
	 *            element.
121
	 */
122
	public void consumeContentBinding(IConfigurationElement element) {
123
		consumeBinding(element, true);
124
	}
125
126
	public boolean isRootExtension(String aContentExtensionId) {
108
	public boolean isRootExtension(String aContentExtensionId) {
127
		return contentBinding.isRootExtension(aContentExtensionId);
109
		return contentBinding.isRootExtension(aContentExtensionId);
128
	}
110
	}
Lines 139-144 Link Here
139
		return actionBinding.isVisibleExtension(anActionExtensionId);
121
		return actionBinding.isVisibleExtension(anActionExtensionId);
140
	}
122
	}
141
123
124
	public boolean isVisibleCommand(String aCommandId) {
125
		return commandBinding.isVisibleExtension(aCommandId);
126
	}
127
142
	public boolean hasOverriddenRootExtensions() {
128
	public boolean hasOverriddenRootExtensions() {
143
		return contentBinding.hasOverriddenRootExtensions();
129
		return contentBinding.hasOverriddenRootExtensions();
144
	}
130
	}
Lines 237-242 Link Here
237
	}
223
	}
238
	
224
	
239
	/**
225
	/**
226
	 * @param binding
227
	 */
228
	public void setCommandBinding(Binding binding) {
229
		commandBinding = binding;
230
	}
231
	
232
	/**
233
	 * @return the content Binding
234
	 */
235
	public Binding getCommandBinding() {
236
		return commandBinding;
237
	}
238
	
239
	/**
240
	 * @param assistants
240
	 * @param assistants
241
	 */
241
	 */
242
	public void setDragAssistants(Set assistants) {
242
	public void setDragAssistants(Set assistants) {
Lines 328-343 Link Here
328
		return dragAssistants;
328
		return dragAssistants;
329
	}
329
	}
330
330
331
	private void consumeBinding(IConfigurationElement element, boolean isContent) {
331
	/**
332
	 * @param element
333
	 * @param bindingTag
334
	 */
335
	public void consumeBinding(IConfigurationElement element, String bindingTag) {
332
		IConfigurationElement[] includesElement = element
336
		IConfigurationElement[] includesElement = element
333
				.getChildren(TAG_INCLUDES);
337
				.getChildren(TAG_INCLUDES);
334
338
339
		boolean respectRoots = false;
340
		Binding binding = null;
341
		if (bindingTag.equals(TAG_CONTENT_EXTENSION)) {
342
			binding = contentBinding;
343
			respectRoots = true;
344
		} else if (bindingTag.equals(TAG_ACTION_EXTENSION))
345
			binding = actionBinding;
346
		else if (bindingTag.equals(TAG_COMMAND_MENU_EXTENSION))
347
			binding = commandBinding;
348
		
335
		if (includesElement.length == 1) {
349
		if (includesElement.length == 1) {
336
			if (isContent) {
350
			binding.consumeIncludes(includesElement[0], respectRoots);
337
				contentBinding.consumeIncludes(includesElement[0], true);
338
			} else {
339
				actionBinding.consumeIncludes(includesElement[0], false);
340
			}
341
		} else if (includesElement.length >= 1) {
351
		} else if (includesElement.length >= 1) {
342
			NavigatorPlugin.logError(0, NLS.bind(
352
			NavigatorPlugin.logError(0, NLS.bind(
343
					CommonNavigatorMessages.Too_many_elements_Warning,
353
					CommonNavigatorMessages.Too_many_elements_Warning,
Lines 353-364 Link Here
353
				.getChildren(TAG_EXCLUDES);
363
				.getChildren(TAG_EXCLUDES);
354
364
355
		if (excludesElement.length == 1) {
365
		if (excludesElement.length == 1) {
356
366
			binding.consumeExcludes(excludesElement[0]);
357
			if (isContent) {
358
				contentBinding.consumeExcludes(excludesElement[0]);
359
			} else {
360
				actionBinding.consumeExcludes(excludesElement[0]);
361
			}
362
		} else if (excludesElement.length >= 1) {
367
		} else if (excludesElement.length >= 1) {
363
			NavigatorPlugin.logError(0, NLS.bind(
368
			NavigatorPlugin.logError(0, NLS.bind(
364
					CommonNavigatorMessages.Too_many_elements_Warning,
369
					CommonNavigatorMessages.Too_many_elements_Warning,
Lines 371-374 Link Here
371
		}
376
		}
372
	}
377
	}
373
378
379
	void setupFromParent(NavigatorViewerDescriptor parentDesc) {
380
		setActionBinding(parentDesc.getActionBinding());
381
		setContentBinding(parentDesc.getContentBinding());
382
		setCommandBinding(parentDesc.getCommandBinding());
383
		setDragAssistants(parentDesc.getDragAssistants());
384
	}
385
	
374
}
386
}
(-)src/org/eclipse/ui/internal/navigator/extensions/NavigatorViewerDescriptorManager.java (-6 / +14 lines)
Lines 46-54 Link Here
46
			NavigatorViewerDescriptor desc = (NavigatorViewerDescriptor) it.next();
46
			NavigatorViewerDescriptor desc = (NavigatorViewerDescriptor) it.next();
47
			NavigatorViewerDescriptor parentDesc = (NavigatorViewerDescriptor) viewerDescriptors.get(desc.getInheritBindingsFromViewer());
47
			NavigatorViewerDescriptor parentDesc = (NavigatorViewerDescriptor) viewerDescriptors.get(desc.getInheritBindingsFromViewer());
48
			if (parentDesc != null) {
48
			if (parentDesc != null) {
49
				desc.setActionBinding(parentDesc.getActionBinding());
49
				desc.setupFromParent(parentDesc);
50
				desc.setContentBinding(parentDesc.getContentBinding());
51
				desc.setDragAssistants(parentDesc.getDragAssistants());
52
			}
50
			}
53
		}
51
		}
54
	}
52
	}
Lines 179-196 Link Here
179
				}
177
				}
180
				return true;
178
				return true;
181
			}
179
			}
180
			
181
			System.out.println("name: " + element.getName()); //$NON-NLS-1$
182
			
182
			if (TAG_VIEWER_CONTENT_BINDING.equals(element.getName())) {
183
			if (TAG_VIEWER_CONTENT_BINDING.equals(element.getName())) {
183
				String viewerId = element.getAttribute(ATT_VIEWER_ID);
184
				String viewerId = element.getAttribute(ATT_VIEWER_ID);
184
				NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId);
185
				NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId);
185
				descriptor.consumeContentBinding(element);
186
				descriptor.consumeBinding(element, NavigatorViewerDescriptor.TAG_CONTENT_EXTENSION);
186
				return true;
187
				return true;
187
			}
188
			}
188
			if (TAG_VIEWER_ACTION_BINDING.equals(element.getName())) {
189
			if (TAG_VIEWER_ACTION_BINDING.equals(element.getName())) {
189
				String viewerId = element.getAttribute(ATT_VIEWER_ID);
190
				String viewerId = element.getAttribute(ATT_VIEWER_ID);
190
				NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId);
191
				NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId);
191
				descriptor.consumeActionBinding(element);
192
				descriptor.consumeBinding(element, NavigatorViewerDescriptor.TAG_ACTION_EXTENSION);
192
				return true;
193
				return true;
193
			} if (TAG_DRAG_ASSISTANT.equals(element.getName())) {
194
			}
195
			if (TAG_VIEWER_COMMAND_BINDING.equals(element.getName())) {
196
				String viewerId = element.getAttribute(ATT_VIEWER_ID);
197
				NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId);
198
				descriptor.consumeBinding(element, NavigatorViewerDescriptor.TAG_COMMAND_MENU_EXTENSION);
199
				return true;
200
			}
201
			if (TAG_DRAG_ASSISTANT.equals(element.getName())) {
194
				String viewerId = element.getAttribute(ATT_VIEWER_ID);
202
				String viewerId = element.getAttribute(ATT_VIEWER_ID);
195
				NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId);
203
				NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId);
196
				descriptor.addDragAssistant(new CommonDragAssistantDescriptor(element));
204
				descriptor.addDragAssistant(new CommonDragAssistantDescriptor(element));
(-)src/org/eclipse/ui/navigator/CommonNavigator.java (+12 lines)
Lines 12-17 Link Here
12
 *******************************************************************************/
12
 *******************************************************************************/
13
package org.eclipse.ui.navigator;
13
package org.eclipse.ui.navigator;
14
14
15
import org.eclipse.core.commands.IHandler;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.PerformanceStats;
17
import org.eclipse.core.runtime.PerformanceStats;
17
import org.eclipse.jface.action.IAction;
18
import org.eclipse.jface.action.IAction;
Lines 432-437 Link Here
432
		return super.getAdapter(adapter);
433
		return super.getAdapter(adapter);
433
	}
434
	}
434
435
436
	
437
	/**
438
	 * @param commandId
439
	 * @param handler
440
	 * 
441
	 * @since 3.5
442
	 */
443
	public void bindHandler(String commandId, IHandler handler) {
444
		
445
	}
446
	
435
    /**
447
    /**
436
     * Returns the <code>IShowInSource</code> for this view.
448
     * Returns the <code>IShowInSource</code> for this view.
437
     */
449
     */
(-)src/org/eclipse/ui/navigator/CommonViewer.java (+1 lines)
Lines 109-114 Link Here
109
		setContentProvider(contentService.createCommonContentProvider());
109
		setContentProvider(contentService.createCommonContentProvider());
110
		setLabelProvider(new NavigatorDecoratingLabelProvider(contentService.createCommonLabelProvider()));
110
		setLabelProvider(new NavigatorDecoratingLabelProvider(contentService.createCommonLabelProvider()));
111
		initDragAndDrop();
111
		initDragAndDrop();
112
		contentService.bindCommandMenuContributions(this);
112
	}
113
	}
113
114
114
	void setCommonNavigator(CommonNavigator navigator) {
115
	void setCommonNavigator(CommonNavigator navigator) {
(-)src/org/eclipse/ui/navigator/INavigatorViewerDescriptor.java (+13 lines)
Lines 93-98 Link Here
93
	boolean isVisibleActionExtension(String anActionExtensionId);
93
	boolean isVisibleActionExtension(String anActionExtensionId);
94
94
95
	/**
95
	/**
96
	 * Returns true if a command with the given id is 'visible'. A command
97
	 * is 'visible' if it matches a viewerCommandMenuBinding for the
98
	 * given viewer id.
99
	 * 
100
	 * @param aCommandId
101
	 *            The id to query
102
	 * @return True if the command id matches a viewerCommandMenuBinding for
103
	 *         the viewer id of this descriptor.
104
	 * @since 3.5
105
	 */
106
	boolean isVisibleCommand(String aCommandId);
107
108
	/**
96
	 * Returns true if the content extension of the given id matches a
109
	 * Returns true if the content extension of the given id matches a
97
	 * viewerContentBinding extension that declares isRoot as true.
110
	 * viewerContentBinding extension that declares isRoot as true.
98
	 * 
111
	 * 
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 2-8 Link Here
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %Plugin.name
3
Bundle-Name: %Plugin.name
4
Bundle-SymbolicName: org.eclipse.ui.navigator.resources; singleton:=true
4
Bundle-SymbolicName: org.eclipse.ui.navigator.resources; singleton:=true
5
Bundle-Version: 3.4.200.qualifier
5
Bundle-Version: 3.5.0.qualifier
6
Bundle-Activator: org.eclipse.ui.internal.navigator.resources.plugin.WorkbenchNavigatorPlugin
6
Bundle-Activator: org.eclipse.ui.internal.navigator.resources.plugin.WorkbenchNavigatorPlugin
7
Bundle-Vendor: %Plugin.providerName
7
Bundle-Vendor: %Plugin.providerName
8
Bundle-Localization: plugin
8
Bundle-Localization: plugin
(-)plugin.properties (+2 lines)
Lines 15-20 Link Here
15
resourceGoTo.extension.name=Resources Go To
15
resourceGoTo.extension.name=Resources Go To
16
workingsets.extension.name=Working Sets
16
workingsets.extension.name=Working Sets
17
Common_Resource_Navigator=Project Explorer
17
Common_Resource_Navigator=Project Explorer
18
19
command.goToResource=Go To Resource
18
 
20
 
19
filters.startsWithDot.name=.* resources
21
filters.startsWithDot.name=.* resources
20
filters.startsWithDot.description=Hides resources that begin with "."
22
filters.startsWithDot.description=Hides resources that begin with "."
(-)plugin.xml (-1 / +20 lines)
Lines 58-63 Link Here
58
           <contentExtension pattern="org.eclipse.ui.navigator.resources.workingSets"/>
58
           <contentExtension pattern="org.eclipse.ui.navigator.resources.workingSets"/>
59
          </includes>
59
          </includes>
60
       </viewerContentBinding>
60
       </viewerContentBinding>
61
       <viewerCommandMenuBinding
62
             viewerId="org.eclipse.ui.navigator.ProjectExplorer">
63
          <includes>
64
             <commandMenuExtension
65
                   pattern="org.eclipse.ui.navigate.goToResource">
66
             </commandMenuExtension>
67
          </includes>
68
       </viewerCommandMenuBinding>
69
       <viewerHandlerBinding
70
             viewerId="org.eclipse.ui.navigator.ProjectExplorer">
71
          <includes>
72
             <handler
73
                   pattern="org.eclipse.ui.navigate.goToResource">
74
             </handler>
75
          </includes>
76
       </viewerHandlerBinding>
61
       <viewerActionBinding
77
       <viewerActionBinding
62
            viewerId="org.eclipse.ui.navigator.ProjectExplorer">
78
            viewerId="org.eclipse.ui.navigator.ProjectExplorer">
63
         <includes>
79
         <includes>
Lines 313-318 Link Here
313
               class="org.eclipse.ui.internal.navigator.workingsets.WorkingSetSorter"
329
               class="org.eclipse.ui.internal.navigator.workingsets.WorkingSetSorter"
314
               id="org.eclipse.ui.navigator.resources.workingSets.sorter"/>  
330
               id="org.eclipse.ui.navigator.resources.workingSets.sorter"/>  
315
      </navigatorContent>
331
      </navigatorContent>
332
      <commandMenuContribution
333
            commandId="org.eclipse.ui.navigate.goToResource">
334
      </commandMenuContribution>
316
      
335
      
317
   </extension>
336
   </extension>
318
    <extension
337
    <extension
Lines 373-377 Link Here
373
    	<perspectiveExtension targetID = "org.eclipse.ui.resourcePerspective">
392
    	<perspectiveExtension targetID = "org.eclipse.ui.resourcePerspective">
374
		    <showInPart id = "org.eclipse.ui.navigator.ProjectExplorer"/>
393
		    <showInPart id = "org.eclipse.ui.navigator.ProjectExplorer"/>
375
    	</perspectiveExtension>
394
    	</perspectiveExtension>
376
   	</extension>    
395
   	</extension>
377
</plugin> 
396
</plugin> 
(-)src/org/eclipse/ui/navigator/resources/CopyHandler.java (+238 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.navigator.resources;
12
13
import java.util.Iterator;
14
import java.util.List;
15
16
import org.eclipse.core.commands.AbstractHandler;
17
import org.eclipse.core.commands.ExecutionEvent;
18
import org.eclipse.core.commands.ExecutionException;
19
import org.eclipse.core.resources.IContainer;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.runtime.Assert;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.jface.dialogs.MessageDialog;
24
import org.eclipse.jface.viewers.IStructuredSelection;
25
import org.eclipse.swt.SWTError;
26
import org.eclipse.swt.dnd.Clipboard;
27
import org.eclipse.swt.dnd.DND;
28
import org.eclipse.swt.dnd.FileTransfer;
29
import org.eclipse.swt.dnd.TextTransfer;
30
import org.eclipse.swt.dnd.Transfer;
31
import org.eclipse.swt.widgets.Shell;
32
import org.eclipse.ui.PlatformUI;
33
import org.eclipse.ui.actions.SelectionListenerAction;
34
import org.eclipse.ui.part.ResourceTransfer;
35
import org.eclipse.ui.internal.navigator.resources.plugin.WorkbenchNavigatorMessages;
36
37
/**
38
 * Standard action for copying the currently selected resources to the clipboard.
39
 * <p>
40
 * This class may be instantiated; it is not intended to be subclassed.
41
 * </p>
42
 * 
43
 * @since 3.5
44
 */
45
public class CopyHandler extends AbstractHandler {
46
47
    /**
48
     * The id of this action.
49
     */
50
    public static final String ID = PlatformUI.PLUGIN_ID + ".CopyAction"; //$NON-NLS-1$
51
52
    /**
53
     * The shell in which to show any dialogs.
54
     */
55
    private Shell shell;
56
57
    /**
58
     * System clipboard
59
     */
60
    private Clipboard clipboard;
61
62
    /**
63
     * Associated paste action. May be <code>null</code>
64
     */
65
    private PasteHandler pasteAction;
66
67
    /**
68
     * Creates a new action.
69
     *
70
     * @param shell the shell for any dialogs
71
     * @param clipboard a platform clipboard
72
     */
73
    public CopyHandler(Shell shell, Clipboard clipboard) {
74
        super(WorkbenchNavigatorMessages.CopyAction_Cop_); 
75
        Assert.isNotNull(shell);
76
        Assert.isNotNull(clipboard);
77
        this.shell = shell;
78
        this.clipboard = clipboard;
79
        setToolTipText(WorkbenchNavigatorMessages.CopyAction_Copy_selected_resource_s_); 
80
        setId(CopyHandler.ID);
81
        PlatformUI.getWorkbench().getHelpSystem().setHelp(this, "CopyHelpId"); //$NON-NLS-1$
82
				// TODO INavigatorHelpContextIds.COPY_ACTION);
83
    }
84
85
    /**
86
     * Creates a new action.
87
     *
88
     * @param shell the shell for any dialogs
89
     * @param clipboard a platform clipboard
90
     * @param pasteAction a paste action
91
     * 
92
     * @since 2.0
93
     */
94
    public CopyHandler(Shell shell, Clipboard clipboard, PasteHandler pasteAction) {
95
        this(shell, clipboard);
96
        this.pasteAction = pasteAction;
97
    }
98
99
    /**
100
     * The <code>CopyAction</code> implementation of this method defined 
101
     * on <code>IAction</code> copies the selected resources to the 
102
     * clipboard.
103
     */
104
	/* (non-Javadoc)
105
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
106
	 */
107
	public Object execute(ExecutionEvent event) throws ExecutionException {
108
        List selectedResources = getSelectedResources();
109
        IResource[] resources = (IResource[]) selectedResources
110
                .toArray(new IResource[selectedResources.size()]);
111
112
        // Get the file names and a string representation
113
        final int length = resources.length;
114
        int actualLength = 0;
115
        String[] fileNames = new String[length];
116
        StringBuffer buf = new StringBuffer();
117
        for (int i = 0; i < length; i++) {
118
            IPath location = resources[i].getLocation();
119
            // location may be null. See bug 29491.
120
            if (location != null) {
121
				fileNames[actualLength++] = location.toOSString();
122
			}
123
            if (i > 0) {
124
				buf.append("\n"); //$NON-NLS-1$
125
			}
126
            buf.append(resources[i].getName());
127
        }
128
        // was one or more of the locations null?
129
        if (actualLength < length) {
130
            String[] tempFileNames = fileNames;
131
            fileNames = new String[actualLength];
132
            for (int i = 0; i < actualLength; i++) {
133
				fileNames[i] = tempFileNames[i];
134
			}
135
        }
136
        setClipboard(resources, fileNames, buf.toString());
137
138
        // update the enablement of the paste action
139
        // workaround since the clipboard does not suppot callbacks
140
        if (pasteAction != null && pasteAction.getStructuredSelection() != null) {
141
			pasteAction.selectionChanged(pasteAction.getStructuredSelection());
142
		}
143
        return null;
144
        
145
    }
146
147
    /**
148
     * Set the clipboard contents. Prompt to retry if clipboard is busy.
149
     * 
150
     * @param resources the resources to copy to the clipboard
151
     * @param fileNames file names of the resources to copy to the clipboard
152
     * @param names string representation of all names
153
     */
154
    private void setClipboard(IResource[] resources, String[] fileNames,
155
            String names) {
156
        try {
157
            // set the clipboard contents
158
            if (fileNames.length > 0) {
159
                clipboard.setContents(new Object[] { resources, fileNames,
160
                        names },
161
                        new Transfer[] { ResourceTransfer.getInstance(),
162
                                FileTransfer.getInstance(),
163
                                TextTransfer.getInstance() });
164
            } else {
165
                clipboard.setContents(new Object[] { resources, names },
166
                        new Transfer[] { ResourceTransfer.getInstance(),
167
                                TextTransfer.getInstance() });
168
            }
169
        } catch (SWTError e) {
170
            if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
171
				throw e;
172
			}
173
            if (MessageDialog
174
                    .openQuestion(
175
                            shell,
176
                            "Problem with copy title", // TODO ResourceNavigatorMessages.CopyToClipboardProblemDialog_title,  //$NON-NLS-1$
177
                            "Problem with copy.")) { //$NON-NLS-1$
178
				setClipboard(resources, fileNames, names);
179
			}
180
        }
181
    }
182
183
    /**
184
     * The <code>CopyAction</code> implementation of this
185
     * <code>SelectionListenerAction</code> method enables this action if 
186
     * one or more resources of compatible types are selected.
187
     */
188
    protected boolean updateSelection(IStructuredSelection selection) {
189
        if (!super.updateSelection(selection)) {
190
			return false;
191
		}
192
193
        if (getSelectedNonResources().size() > 0) {
194
			return false;
195
		}
196
197
        List selectedResources = getSelectedResources();
198
        if (selectedResources.size() == 0) {
199
			return false;
200
		}
201
202
        boolean projSelected = selectionIsOfType(IResource.PROJECT);
203
        boolean fileFoldersSelected = selectionIsOfType(IResource.FILE
204
                | IResource.FOLDER);
205
        if (!projSelected && !fileFoldersSelected) {
206
			return false;
207
		}
208
209
        // selection must be homogeneous
210
        if (projSelected && fileFoldersSelected) {
211
			return false;
212
		}
213
214
        // must have a common parent	
215
        IContainer firstParent = ((IResource) selectedResources.get(0))
216
                .getParent();
217
        if (firstParent == null) {
218
			return false;
219
		}
220
221
        Iterator resourcesEnum = selectedResources.iterator();
222
        while (resourcesEnum.hasNext()) {
223
            IResource currentResource = (IResource) resourcesEnum.next();
224
            if (!currentResource.getParent().equals(firstParent)) {
225
				return false;
226
			}
227
            // resource location must exist
228
            if (currentResource.getLocationURI() == null) {
229
				return false;
230
			}
231
        }
232
233
        return true;
234
    }
235
236
237
}
238
(-)src/org/eclipse/ui/navigator/resources/PasteHandler.java (+275 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.navigator.resources;
12
13
import java.util.List;
14
15
import org.eclipse.core.commands.AbstractHandler;
16
import org.eclipse.core.commands.ExecutionEvent;
17
import org.eclipse.core.commands.ExecutionException;
18
import org.eclipse.core.resources.IContainer;
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.runtime.Assert;
23
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.swt.dnd.Clipboard;
25
import org.eclipse.swt.dnd.FileTransfer;
26
import org.eclipse.swt.dnd.TransferData;
27
import org.eclipse.swt.widgets.Shell;
28
import org.eclipse.ui.PlatformUI;
29
import org.eclipse.ui.actions.CopyFilesAndFoldersOperation;
30
import org.eclipse.ui.actions.CopyProjectOperation;
31
import org.eclipse.ui.actions.SelectionListenerAction;
32
import org.eclipse.ui.part.ResourceTransfer;
33
import org.eclipse.ui.internal.navigator.resources.plugin.WorkbenchNavigatorMessages;
34
35
/**
36
 * Standard action for pasting resources on the clipboard to the selected resource's location.
37
 * <p>
38
 * This class may be instantiated; it is not intended to be subclassed.
39
 * </p>
40
 * 
41
 * @since 3.5
42
 */
43
public class PasteHandler extends AbstractHandler {
44
45
    /**
46
     * The id of this action.
47
     */
48
    public static final String ID = PlatformUI.PLUGIN_ID + ".PasteAction";//$NON-NLS-1$
49
50
    /**
51
     * The shell in which to show any dialogs.
52
     */
53
    private Shell shell;
54
55
    /**
56
     * System clipboard
57
     */
58
    private Clipboard clipboard;
59
60
    /**
61
     * Creates a new action.
62
     *
63
     * @param shell the shell for any dialogs
64
     * @param clipboard the clipboard
65
     */
66
    public PasteHandler(Shell shell, Clipboard clipboard) {
67
        super(WorkbenchNavigatorMessages.PasteAction_Past_); 
68
        Assert.isNotNull(shell);
69
        Assert.isNotNull(clipboard);
70
        this.shell = shell;
71
        this.clipboard = clipboard;
72
        setToolTipText(WorkbenchNavigatorMessages.PasteAction_Paste_selected_resource_s_); 
73
        setId(PasteHandler.ID);
74
        PlatformUI.getWorkbench().getHelpSystem().setHelp(this, "HelpId"); //$NON-NLS-1$
75
				// TODO INavigatorHelpContextIds.PASTE_ACTION);
76
    }
77
78
    /**
79
     * Returns the actual target of the paste action. Returns null
80
     * if no valid target is selected.
81
     * 
82
     * @return the actual target of the paste action
83
     */
84
    private IResource getTarget() {
85
        List selectedResources = getSelectedResources();
86
87
        for (int i = 0; i < selectedResources.size(); i++) {
88
            IResource resource = (IResource) selectedResources.get(i);
89
90
            if (resource instanceof IProject && !((IProject) resource).isOpen()) {
91
				return null;
92
			}
93
            if (resource.getType() == IResource.FILE) {
94
				resource = resource.getParent();
95
			}
96
            if (resource != null) {
97
				return resource;
98
			}
99
        }
100
        return null;
101
    }
102
103
    /**
104
     * Returns whether any of the given resources are linked resources.
105
     * 
106
     * @param resources resource to check for linked type. may be null
107
     * @return true=one or more resources are linked. false=none of the 
108
     * 	resources are linked
109
     */
110
    private boolean isLinked(IResource[] resources) {
111
        for (int i = 0; i < resources.length; i++) {
112
            if (resources[i].isLinked()) {
113
				return true;
114
			}
115
        }
116
        return false;
117
    }
118
119
	/* (non-Javadoc)
120
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
121
	 */
122
	public Object execute(ExecutionEvent event) throws ExecutionException {
123
		// TODO Auto-generated method stub
124
		return null;
125
	}
126
127
	/**
128
     * Implementation of method defined on <code>IAction</code>.
129
     */
130
    public void run() {
131
        // try a resource transfer
132
        ResourceTransfer resTransfer = ResourceTransfer.getInstance();
133
        IResource[] resourceData = (IResource[]) clipboard
134
                .getContents(resTransfer);
135
136
        if (resourceData != null && resourceData.length > 0) {
137
            if (resourceData[0].getType() == IResource.PROJECT) {
138
                // enablement checks for all projects
139
                for (int i = 0; i < resourceData.length; i++) {
140
                    CopyProjectOperation operation = new CopyProjectOperation(
141
                            this.shell);
142
                    operation.copyProject((IProject) resourceData[i]);
143
                }
144
            } else {
145
                // enablement should ensure that we always have access to a container
146
                IContainer container = getContainer();
147
148
                CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(
149
                        this.shell);
150
                operation.copyResources(resourceData, container);
151
            }
152
            return;
153
        }
154
155
        // try a file transfer
156
        FileTransfer fileTransfer = FileTransfer.getInstance();
157
        String[] fileData = (String[]) clipboard.getContents(fileTransfer);
158
159
        if (fileData != null) {
160
            // enablement should ensure that we always have access to a container
161
            IContainer container = getContainer();
162
163
            CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(
164
                    this.shell);
165
            operation.copyFiles(fileData, container);
166
        }
167
    }
168
169
    /**
170
     * Returns the container to hold the pasted resources.
171
     */
172
    private IContainer getContainer() {
173
        List selection = getSelectedResources();
174
        if (selection.get(0) instanceof IFile) {
175
			return ((IFile) selection.get(0)).getParent();
176
		}
177
        return (IContainer) selection.get(0);
178
    }
179
180
    /**
181
     * The <code>PasteAction</code> implementation of this
182
     * <code>SelectionListenerAction</code> method enables this action if 
183
     * a resource compatible with what is on the clipboard is selected.
184
     * 
185
     * -Clipboard must have IResource or java.io.File
186
     * -Projects can always be pasted if they are open
187
     * -Workspace folder may not be copied into itself
188
     * -Files and folders may be pasted to a single selected folder in open 
189
     * 	project or multiple selected files in the same folder 
190
     */
191
    protected boolean updateSelection(IStructuredSelection selection) {
192
        if (!super.updateSelection(selection)) {
193
			return false;
194
		}
195
196
        final IResource[][] clipboardData = new IResource[1][];
197
        shell.getDisplay().syncExec(new Runnable() {
198
            public void run() {
199
                // clipboard must have resources or files
200
                ResourceTransfer resTransfer = ResourceTransfer.getInstance();
201
                clipboardData[0] = (IResource[]) clipboard
202
                        .getContents(resTransfer);
203
            }
204
        });
205
        IResource[] resourceData = clipboardData[0];
206
        boolean isProjectRes = resourceData != null && resourceData.length > 0
207
                && resourceData[0].getType() == IResource.PROJECT;
208
209
        if (isProjectRes) {
210
            for (int i = 0; i < resourceData.length; i++) {
211
                // make sure all resource data are open projects
212
                // can paste open projects regardless of selection
213
                if (resourceData[i].getType() != IResource.PROJECT
214
                        || ((IProject) resourceData[i]).isOpen() == false) {
215
					return false;
216
				}
217
            }
218
            return true;
219
        }
220
221
        if (getSelectedNonResources().size() > 0) {
222
			return false;
223
		}
224
225
        IResource targetResource = getTarget();
226
        // targetResource is null if no valid target is selected (e.g., open project) 
227
        // or selection is empty	
228
        if (targetResource == null) {
229
			return false;
230
		}
231
232
        // can paste files and folders to a single selection (file, folder, 
233
        // open project) or multiple file selection with the same parent
234
        List selectedResources = getSelectedResources();
235
        if (selectedResources.size() > 1) {
236
            for (int i = 0; i < selectedResources.size(); i++) {
237
                IResource resource = (IResource) selectedResources.get(i);
238
                if (resource.getType() != IResource.FILE) {
239
					return false;
240
				}
241
                if (!targetResource.equals(resource.getParent())) {
242
					return false;
243
				}
244
            }
245
        }
246
        if (resourceData != null) {
247
            // linked resources can only be pasted into projects
248
            if (isLinked(resourceData)
249
                && targetResource.getType() != IResource.PROJECT
250
                && targetResource.getType() != IResource.FOLDER) {
251
				return false;
252
			}
253
254
            if (targetResource.getType() == IResource.FOLDER) {
255
                // don't try to copy folder to self
256
                for (int i = 0; i < resourceData.length; i++) {
257
                    if (targetResource.equals(resourceData[i])) {
258
						return false;
259
					}
260
                }
261
            }
262
            return true;
263
        }
264
        TransferData[] transfers = clipboard.getAvailableTypes();
265
        FileTransfer fileTransfer = FileTransfer.getInstance();
266
        for (int i = 0; i < transfers.length; i++) {
267
            if (fileTransfer.isSupportedType(transfers[i])) {
268
				return true;
269
			}
270
        }
271
        return false;
272
    }
273
274
}
275

Return to bug 304925