Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 265bd6fc9f1026bcc024b4ba14c08e768c951cdb (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*******************************************************************************
 * Copyright (c) 2000, 2010 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.tags;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.team.internal.ccvs.core.CVSTag;
import org.eclipse.team.internal.ccvs.ui.*;
import org.eclipse.team.internal.ccvs.ui.wizards.CVSWizardPage;
import org.eclipse.team.internal.ui.PixelConverter;
import org.eclipse.team.internal.ui.SWTUtils;
import org.eclipse.ui.PlatformUI;

/**
 * General tag selection page that allows the selection of a tag
 * for a particular remote folder
 */
public class TagSelectionWizardPage extends CVSWizardPage {

	private CVSTag selectedTag;
	
	// Needed to dynamicaly create refresh buttons
	private Composite composite;
	
	private int includeFlags;
	
	// Fields for allowing the use of the tag from the local workspace
	boolean allowNoTag = false;
	private Button useResourceTagButton;
	private Button selectTagButton;
	private boolean useResourceTag = false;
	private String helpContextId;
    private TagSelectionArea tagArea;
    private TagSource tagSource;
	
	public TagSelectionWizardPage(String pageName, String title, ImageDescriptor titleImage, String description, TagSource tagSource, int includeFlags) {
		super(pageName, title, titleImage, description);
        this.tagSource = tagSource;
		this.includeFlags = includeFlags;
	}

	/**
	 * Set the help context for the tag selection page. 
	 * This method must be invoked before <code>createControl</code>
	 * @param helpContextId the help context id
	 */
	public void setHelpContxtId(String helpContextId) {
		this.helpContextId = helpContextId;
	}
    
	@Override
	public void createControl(Composite parent) {
		
		final PixelConverter converter= SWTUtils.createDialogPixelConverter(parent);
		
		composite= new Composite(parent, SWT.NONE);
		composite.setLayout(SWTUtils.createGridLayout(1, converter, SWTUtils.MARGINS_DEFAULT));
		composite.setLayoutData(SWTUtils.createHVFillGridData());
		setControl(composite);
		
		// set F1 help
		if (helpContextId != null)
            PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, helpContextId);
		
		if (allowNoTag) {
			SelectionListener listener = new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					useResourceTag = useResourceTagButton.getSelection();
					updateEnablement();
				}
			};
			useResourceTag = true;
			useResourceTagButton = createRadioButton(composite, CVSUIMessages.TagSelectionWizardPage_0, 1); 
			selectTagButton = createRadioButton(composite, CVSUIMessages.TagSelectionWizardPage_1, 1); 
			useResourceTagButton.setSelection(useResourceTag);
			selectTagButton.setSelection(!useResourceTag);
			useResourceTagButton.addSelectionListener(listener);
			selectTagButton.addSelectionListener(listener);
		}
		
		createTagArea();
		updateEnablement();
		Dialog.applyDialogFont(parent);	
	}
	
	private void createTagArea() {
		tagArea = new TagSelectionArea(getShell(), tagSource, includeFlags, null);
	    tagArea.setRunnableContext(getContainer());
		tagArea.createArea(composite);
		tagArea.addPropertyChangeListener(new IPropertyChangeListener() {
            @Override
			public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(TagSelectionArea.SELECTED_TAG)) {
                    selectedTag = tagArea.getSelection();
    				updateEnablement();
                } else if (event.getProperty().equals(TagSelectionArea.OPEN_SELECTED_TAG)) {
                    if (selectedTag != null)
                        gotoNextPage();
                }

            }
        });
		refreshTagArea();
    }

    private void refreshTagArea() {
        if (tagArea != null) {
            tagArea.refresh();
            tagArea.setSelection(selectedTag);
        }
	}
	
	protected void updateEnablement() {
		tagArea.setEnabled(!useResourceTag);
		setPageComplete(useResourceTag || selectedTag != null);
	}
	
	public CVSTag getSelectedTag() {
		if (useResourceTag) 
			return null;
		return selectedTag;
	}
	
	protected void gotoNextPage() {
		TagSelectionWizardPage.this.getContainer().showPage(getNextPage());
	}
	
	public void setAllowNoTag(boolean b) {
		allowNoTag = b;
	}
	
	@Override
	public void setVisible(boolean visible) {
		super.setVisible(visible);

		if (visible && tagArea != null) {
			tagArea.setFocus();
			if (CVSUIPlugin.getPlugin().getPreferenceStore().getBoolean(ICVSUIConstants.PREF_AUTO_REFRESH_TAGS_IN_TAG_SELECTION_DIALOG)) {
				tagArea.refreshTagList();
			}
		}
	}

    /**
     * Set the tag source used by this wizard page
     * @param source the tag source
     */
    public void setTagSource(TagSource source) {
        this.tagSource = source;
        tagArea.setTagSource(tagSource);
        setSelection(null);
        refreshTagArea();
    }

    /**
     * Set the selection of the page to the given tag
     * @param selectedTag
     */
    public void setSelection(CVSTag selectedTag) {
		if (selectedTag == null && (includeFlags & TagSelectionArea.INCLUDE_HEAD_TAG) > 0) {
			this.selectedTag = CVSTag.DEFAULT;
		} else {
		    this.selectedTag = selectedTag;
		}
    }
}

Back to the top