KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > wizards > CommitWizardParticipant


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.wizards;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.resources.IFile;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.jface.operation.IRunnableContext;
19 import org.eclipse.jface.operation.IRunnableWithProgress;
20 import org.eclipse.jface.viewers.ILabelDecorator;
21 import org.eclipse.swt.widgets.Display;
22 import org.eclipse.team.internal.ccvs.ui.CVSDecoration;
23 import org.eclipse.team.internal.ccvs.ui.subscriber.CVSParticipantLabelDecorator;
24 import org.eclipse.team.internal.ccvs.ui.subscriber.WorkspaceSynchronizeParticipant;
25 import org.eclipse.team.internal.ui.synchronize.ChangeSetCapability;
26 import org.eclipse.team.ui.synchronize.*;
27
28 /**
29  * A participant that uses our decorator instead of the standard one.
30  */

31 public class CommitWizardParticipant extends WorkspaceSynchronizeParticipant {
32     
33     /**
34      * The actions to be displayed in the context menu.
35      */

36     private class ActionContribution extends SynchronizePageActionGroup {
37         public void modelChanged(final ISynchronizeModelElement root) {
38             super.modelChanged(root);
39             Display.getDefault().asyncExec(new Runnable JavaDoc() {
40                 public void run() {
41                     final CommitWizardCommitPage page= fWizard.getCommitPage();
42                     if (page != null)
43                         page.updateForModelChange();
44                 }
45             });
46         }
47     }
48
49     /**
50      * An extension of the standard label decorator which configures the keyword substitution
51      * mode according to the settings on the file type wizard page.
52      */

53     private static class Decorator extends CVSParticipantLabelDecorator {
54         
55         private final CommitWizard fWizard;
56
57         public Decorator(ISynchronizePageConfiguration configuration, CommitWizard wizard) {
58             super(configuration);
59             fWizard= wizard;
60         }
61         
62         protected CVSDecoration getDecoration(IResource resource) throws CoreException {
63             final CVSDecoration decoration= super.getDecoration(resource);
64             final CommitWizardFileTypePage page= fWizard.getFileTypePage();
65             
66             if (page != null && resource instanceof IFile)
67                 decoration.setKeywordSubstitution(page.getOption((IFile)resource).getShortDisplayText());
68             return decoration;
69         }
70     }
71     
72     final CommitWizard fWizard;
73     
74     public CommitWizardParticipant(ISynchronizeScope scope, CommitWizard wizard) {
75         super(scope);
76         fWizard= wizard;
77     }
78     
79     protected ILabelDecorator getLabelDecorator(ISynchronizePageConfiguration configuration) {
80         return new Decorator(configuration, fWizard);
81     }
82     
83     public ChangeSetCapability getChangeSetCapability() {
84         return null; // we don't want that button
85
}
86     /* (non-Javadoc)
87      * @see org.eclipse.team.internal.ccvs.ui.subscriber.WorkspaceSynchronizeParticipant#initializeConfiguration(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration)
88      */

89     protected void initializeConfiguration( ISynchronizePageConfiguration configuration) {
90         super.initializeConfiguration(configuration);
91         configuration.setProperty(ISynchronizePageConfiguration.P_TOOLBAR_MENU, new String JavaDoc[] {ISynchronizePageConfiguration.LAYOUT_GROUP});
92         configuration.setProperty(ISynchronizePageConfiguration.P_CONTEXT_MENU, ISynchronizePageConfiguration.DEFAULT_CONTEXT_MENU);
93         configuration.addMenuGroup(
94                 ISynchronizePageConfiguration.P_CONTEXT_MENU,
95                 CONTEXT_MENU_CONTRIBUTION_GROUP_3);
96         configuration.addActionContribution(new ActionContribution());
97         
98         // Wrap the container so that we can update the enablements after the runnable
99
// (i.e. the container resets the state to what it was at the beginning of the
100
// run even if the state of the page changed. Remove from View changes the state)
101
configuration.setRunnableContext(new IRunnableContext() {
102             public void run(boolean fork, boolean cancelable,
103                     IRunnableWithProgress runnable)
104                     throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
105                 fWizard.getContainer().run(fork, cancelable, runnable);
106                 final CommitWizardCommitPage page= fWizard.getCommitPage();
107                 if (page != null)
108                     page.updateEnablements();
109             }
110         });
111         configuration.setSupportedModes(ISynchronizePageConfiguration.OUTGOING_MODE);
112         configuration.setMode(ISynchronizePageConfiguration.OUTGOING_MODE);
113     }
114     /* (non-Javadoc)
115      * @see org.eclipse.team.ui.synchronize.AbstractSynchronizeParticipant#doesSupportSynchronize()
116      */

117     public boolean doesSupportSynchronize() {
118         return false;
119     }
120 }
121
Popular Tags