|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2004, 2007 Mylyn project committers 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 |
|
| 9 |
package org.eclipse.mylyn.internal.team.ui.properties; |
| 10 |
|
| 11 |
import org.eclipse.core.resources.IProject; |
| 12 |
import org.eclipse.core.resources.IResource; |
| 13 |
import org.eclipse.jface.fieldassist.IContentProposalProvider; |
| 14 |
import org.eclipse.jface.fieldassist.IControlContentAdapter; |
| 15 |
import org.eclipse.jface.fieldassist.IControlCreator; |
| 16 |
import org.eclipse.jface.fieldassist.TextContentAdapter; |
| 17 |
import org.eclipse.jface.layout.GridDataFactory; |
| 18 |
import org.eclipse.jface.preference.PreferenceDialog; |
| 19 |
import org.eclipse.jface.resource.JFaceColors; |
| 20 |
import org.eclipse.mylyn.internal.team.ui.FocusedTeamUiPlugin; |
| 21 |
import org.eclipse.mylyn.internal.team.ui.preferences.FocusedTeamPreferencePage; |
| 22 |
import org.eclipse.mylyn.internal.team.ui.templates.TemplateHandlerContentProposalProvider; |
| 23 |
import org.eclipse.swt.SWT; |
| 24 |
import org.eclipse.swt.events.ModifyEvent; |
| 25 |
import org.eclipse.swt.events.ModifyListener; |
| 26 |
import org.eclipse.swt.events.SelectionAdapter; |
| 27 |
import org.eclipse.swt.events.SelectionEvent; |
| 28 |
import org.eclipse.swt.graphics.Font; |
| 29 |
import org.eclipse.swt.layout.GridData; |
| 30 |
import org.eclipse.swt.layout.GridLayout; |
| 31 |
import org.eclipse.swt.widgets.Button; |
| 32 |
import org.eclipse.swt.widgets.Composite; |
| 33 |
import org.eclipse.swt.widgets.Control; |
| 34 |
import org.eclipse.swt.widgets.Label; |
| 35 |
import org.eclipse.swt.widgets.Text; |
| 36 |
import org.eclipse.ui.dialogs.PreferencesUtil; |
| 37 |
import org.eclipse.ui.dialogs.PropertyPage; |
| 38 |
import org.eclipse.ui.fieldassist.ContentAssistField; |
| 39 |
import org.eclipse.ui.forms.events.HyperlinkAdapter; |
| 40 |
import org.eclipse.ui.forms.events.HyperlinkEvent; |
| 41 |
import org.eclipse.ui.forms.widgets.Hyperlink; |
| 42 |
|
| 43 |
/** |
| 44 |
* @author Rob Elves |
| 45 |
* @author Steffen Pingel |
| 46 |
* @see Adapted from org.eclipse.ui.internal.ide.dialogs.ProjectReferencePage |
| 47 |
*/ |
| 48 |
@SuppressWarnings("deprecation") |
| 49 |
public class ProjectTeamPage extends PropertyPage { |
| 50 |
|
| 51 |
private IProject project; |
| 52 |
|
| 53 |
private boolean modified = false; |
| 54 |
|
| 55 |
private Button useProjectSettings; |
| 56 |
|
| 57 |
private Text commitTemplateText; |
| 58 |
|
| 59 |
private Composite propertiesComposite; |
| 60 |
|
| 61 |
private Hyperlink configurationHyperlink; |
| 62 |
|
| 63 |
private Label label; |
| 64 |
|
| 65 |
public ProjectTeamPage() { |
| 66 |
noDefaultAndApplyButton(); |
| 67 |
} |
| 68 |
|
| 69 |
@Override |
| 70 |
protected Control createContents(Composite parent) { |
| 71 |
Font font = parent.getFont(); |
| 72 |
|
| 73 |
Composite composite = new Composite(parent, SWT.NONE); |
| 74 |
GridLayout layout = new GridLayout(); |
| 75 |
composite.setLayout(layout); |
| 76 |
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 77 |
composite.setFont(font); |
| 78 |
|
| 79 |
createDescription(composite); |
| 80 |
createPropertiesControl(composite); |
| 81 |
|
| 82 |
initialize(); |
| 83 |
|
| 84 |
return composite; |
| 85 |
} |
| 86 |
|
| 87 |
private void createDescription(Composite parent) { |
| 88 |
Composite composite = new Composite(parent, SWT.NONE); |
| 89 |
composite.setFont(parent.getFont()); |
| 90 |
GridLayout layout = new GridLayout(); |
| 91 |
layout.marginHeight = 0; |
| 92 |
layout.marginWidth = 0; |
| 93 |
layout.numColumns = 2; |
| 94 |
composite.setLayout(layout); |
| 95 |
composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 96 |
|
| 97 |
useProjectSettings = new Button(composite, SWT.CHECK); |
| 98 |
useProjectSettings.addSelectionListener(new SelectionAdapter() { |
| 99 |
@Override |
| 100 |
public void widgetSelected(SelectionEvent e) { |
| 101 |
modified = true; |
| 102 |
setPropertiesEnabled(useProjectSettings.getSelection()); |
| 103 |
} |
| 104 |
}); |
| 105 |
useProjectSettings.setText("Enable project specific settings"); |
| 106 |
GridDataFactory.fillDefaults().grab(true, false).applyTo(useProjectSettings); |
| 107 |
|
| 108 |
configurationHyperlink = new Hyperlink(composite, SWT.NONE); |
| 109 |
configurationHyperlink.setUnderlined(true); |
| 110 |
configurationHyperlink.setText("Configure workspace"); |
| 111 |
configurationHyperlink.addHyperlinkListener(new HyperlinkAdapter() { |
| 112 |
|
| 113 |
public void linkActivated(HyperlinkEvent e) { |
| 114 |
PreferenceDialog dlg = PreferencesUtil.createPreferenceDialogOn(getShell(), |
| 115 |
FocusedTeamPreferencePage.PAGE_ID, new String[] { FocusedTeamPreferencePage.PAGE_ID }, null); |
| 116 |
dlg.open(); |
| 117 |
} |
| 118 |
}); |
| 119 |
|
| 120 |
Label horizontalLine = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); |
| 121 |
horizontalLine.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1)); |
| 122 |
horizontalLine.setFont(composite.getFont()); |
| 123 |
} |
| 124 |
|
| 125 |
private void setPropertiesEnabled(boolean enabled) { |
| 126 |
propertiesComposite.setEnabled(enabled); |
| 127 |
for (Control child : propertiesComposite.getChildren()) { |
| 128 |
child.setEnabled(enabled); |
| 129 |
} |
| 130 |
commitTemplateText.setEnabled(enabled); |
| 131 |
|
| 132 |
configurationHyperlink.setEnabled(!enabled); |
| 133 |
if (!enabled) { |
| 134 |
configurationHyperlink.setForeground(JFaceColors.getHyperlinkText(getShell().getDisplay())); |
| 135 |
} else { |
| 136 |
configurationHyperlink.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND)); |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
private void createPropertiesControl(Composite parent) { |
| 141 |
propertiesComposite = new Composite(parent, SWT.NONE); |
| 142 |
propertiesComposite.setFont(parent.getFont()); |
| 143 |
GridLayout layout = new GridLayout(); |
| 144 |
layout.marginHeight = 0; |
| 145 |
layout.marginWidth = 0; |
| 146 |
layout.numColumns = 1; |
| 147 |
propertiesComposite.setLayout(layout); |
| 148 |
propertiesComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 149 |
|
| 150 |
label = new Label(propertiesComposite, SWT.NONE); |
| 151 |
label.setText("Commit Comment Template"); |
| 152 |
|
| 153 |
String completedTemplate = ""; //getPreferenceStore().getString(FocusedTeamUiPlugin.COMMIT_TEMPLATE); |
| 154 |
commitTemplateText = addTemplateField(propertiesComposite, completedTemplate, |
| 155 |
new TemplateHandlerContentProposalProvider()); |
| 156 |
} |
| 157 |
|
| 158 |
@SuppressWarnings("deprecation") |
| 159 |
private Text addTemplateField(final Composite parent, final String text, IContentProposalProvider provider) { |
| 160 |
IControlContentAdapter adapter = new TextContentAdapter(); |
| 161 |
IControlCreator controlCreator = new IControlCreator() { |
| 162 |
public Control createControl(Composite parent, int style) { |
| 163 |
Text control = new Text(parent, style); |
| 164 |
control.setText(text); |
| 165 |
control.addModifyListener(new ModifyListener() { |
| 166 |
public void modifyText(ModifyEvent e) { |
| 167 |
modified = true; |
| 168 |
} |
| 169 |
}); |
| 170 |
return control; |
| 171 |
} |
| 172 |
}; |
| 173 |
|
| 174 |
ContentAssistField field = new ContentAssistField(parent, SWT.BORDER | SWT.MULTI, controlCreator, adapter, |
| 175 |
provider, null, new char[] { '$' }); |
| 176 |
|
| 177 |
GridData gd = new GridData(); |
| 178 |
gd.heightHint = 60; |
| 179 |
gd.horizontalAlignment = GridData.FILL; |
| 180 |
gd.grabExcessHorizontalSpace = true; |
| 181 |
gd.verticalAlignment = GridData.CENTER; |
| 182 |
gd.grabExcessVerticalSpace = false; |
| 183 |
field.getLayoutControl().setLayoutData(gd); |
| 184 |
|
| 185 |
return (Text) field.getControl(); |
| 186 |
} |
| 187 |
|
| 188 |
private void initialize() { |
| 189 |
project = (IProject) getElement().getAdapter(IResource.class); |
| 190 |
|
| 191 |
TeamPropertiesLinkProvider provider = new TeamPropertiesLinkProvider(); |
| 192 |
String template = provider.getCommitCommentTemplate(project); |
| 193 |
if (template == null) { |
| 194 |
useProjectSettings.setSelection(false); |
| 195 |
setPropertiesEnabled(false); |
| 196 |
commitTemplateText.setText(FocusedTeamUiPlugin.getDefault().getPreferenceStore().getString( |
| 197 |
FocusedTeamUiPlugin.COMMIT_TEMPLATE)); |
| 198 |
} else { |
| 199 |
useProjectSettings.setSelection(true); |
| 200 |
setPropertiesEnabled(true); |
| 201 |
commitTemplateText.setText(template); |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
@Override |
| 206 |
public boolean performOk() { |
| 207 |
if (!modified) { |
| 208 |
return true; |
| 209 |
} |
| 210 |
|
| 211 |
TeamPropertiesLinkProvider provider = new TeamPropertiesLinkProvider(); |
| 212 |
if (useProjectSettings.getSelection()) { |
| 213 |
provider.setCommitCommentTemplate(project, commitTemplateText.getText()); |
| 214 |
} else { |
| 215 |
provider.setCommitCommentTemplate(project, null); |
| 216 |
} |
| 217 |
|
| 218 |
return true; |
| 219 |
} |
| 220 |
} |