KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > mappings > WorkspaceChangeSetCapability


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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.team.internal.ccvs.ui.mappings;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.jface.window.Window;
18 import org.eclipse.team.core.diff.IDiff;
19 import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
20 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
21 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
22 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
23 import org.eclipse.team.internal.ccvs.ui.subscriber.CommitSetDialog;
24 import org.eclipse.team.internal.core.subscribers.ActiveChangeSet;
25 import org.eclipse.team.internal.core.subscribers.ActiveChangeSetManager;
26 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
27
28 public class WorkspaceChangeSetCapability extends ModelParticipantChangeSetCapability {
29
30     /* (non-Javadoc)
31      * @see org.eclipse.team.internal.ui.synchronize.ChangeSetCapability#supportsActiveChangeSets()
32      */

33     public boolean supportsActiveChangeSets() {
34         return true;
35     }
36     
37     /* (non-Javadoc)
38      * @see org.eclipse.team.internal.ui.synchronize.ChangeSetCapability#enableActiveChangeSetsFor(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration)
39      */

40     public boolean enableActiveChangeSetsFor(ISynchronizePageConfiguration configuration) {
41         return supportsActiveChangeSets() &&
42         configuration.getMode() != ISynchronizePageConfiguration.INCOMING_MODE;
43     }
44     
45     /* (non-Javadoc)
46      * @see org.eclipse.team.internal.ui.synchronize.ChangeSetCapability#createChangeSet(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration, org.eclipse.team.core.diff.IDiff[])
47      */

48     public ActiveChangeSet createChangeSet(ISynchronizePageConfiguration configuration, IDiff[] infos) {
49         ActiveChangeSet set = getActiveChangeSetManager().createSet(CVSUIMessages.WorkspaceChangeSetCapability_1, new IDiff[0]);
50         CommitSetDialog dialog = new CommitSetDialog(configuration.getSite().getShell(), set, getResources(infos), CommitSetDialog.NEW);
51         dialog.open();
52         if (dialog.getReturnCode() != Window.OK) return null;
53         set.add(infos);
54         return set;
55     }
56
57     private IResource[] getResources(IDiff[] diffs) {
58         Set JavaDoc result = new HashSet JavaDoc();
59         for (int i = 0; i < diffs.length; i++) {
60             IDiff diff = diffs[i];
61             IResource resource = ResourceDiffTree.getResourceFor(diff);
62             if (resource != null)
63                 result.add(resource);
64         }
65         return (IResource[]) result.toArray(new IResource[result.size()]);
66     }
67     
68     /* (non-Javadoc)
69      * @see org.eclipse.team.ui.synchronize.ChangeSetCapability#editChangeSet(org.eclipse.team.core.subscribers.ActiveChangeSet)
70      */

71     public void editChangeSet(ISynchronizePageConfiguration configuration, ActiveChangeSet set) {
72         CommitSetDialog dialog = new CommitSetDialog(configuration.getSite().getShell(), set, set.getResources(), CommitSetDialog.EDIT);
73         dialog.open();
74         if (dialog.getReturnCode() != Window.OK) return;
75         // Nothing to do here as the set was updated by the dialog
76
}
77
78     /* (non-Javadoc)
79      * @see org.eclipse.team.ui.synchronize.ChangeSetCapability#getActiveChangeSetManager()
80      */

81     public ActiveChangeSetManager getActiveChangeSetManager() {
82         return CVSUIPlugin.getPlugin().getChangeSetManager();
83     }
84     
85     public CheckedInChangeSetCollector createCheckedInChangeSetCollector(ISynchronizePageConfiguration configuration) {
86         return new CheckedInChangeSetCollector(configuration, CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber());
87     }
88 }
89
Popular Tags