Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2004-08-24 09:58:47 -0400
committerMichael Valenta2004-08-24 09:58:47 -0400
commit5756d260b9cc93da4ac4bbcebb4c34138a545880 (patch)
treee107bebdc93d7abc0fc9d89de4ba3c38bd1cb132
parent42da08ebb65a175053c1f2b88d28ed6dcbcec33a (diff)
downloadeclipse.platform.team-5756d260b9cc93da4ac4bbcebb4c34138a545880.tar.gz
eclipse.platform.team-5756d260b9cc93da4ac4bbcebb4c34138a545880.tar.xz
eclipse.platform.team-5756d260b9cc93da4ac4bbcebb4c34138a545880.zip
Bug 28218 Default provider should prompt in validateEdit if UI context given
-rw-r--r--bundles/org.eclipse.team.core/plugin.xml1
-rw-r--r--bundles/org.eclipse.team.core/schema/defaultFileModificationValidator.exsd103
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileModificationValidatorManager.java36
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java4
-rw-r--r--bundles/org.eclipse.team.ui/plugin.xml4
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/DefaultUIFileModificationValidator.java144
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/dialogs/DetailsDialog.java5
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties5
8 files changed, 295 insertions, 7 deletions
diff --git a/bundles/org.eclipse.team.core/plugin.xml b/bundles/org.eclipse.team.core/plugin.xml
index be80cebe6..45ae9ad2b 100644
--- a/bundles/org.eclipse.team.core/plugin.xml
+++ b/bundles/org.eclipse.team.core/plugin.xml
@@ -23,6 +23,7 @@
<extension-point id="ignore" name="%GlobalIgnoreRegistry" schema="schema/ignore.exsd"/>
<extension-point id="projectSets" name="%TeamProjectSets" schema="schema/projectSets.exsd"/>
<extension-point id="repository" name="%Repository" schema="schema/repository.exsd"/>
+ <extension-point id="defaultFileModificationValidator" name="Default File Modification Validator" schema="schema/defaultFileModificationValidator.exsd"/>
<!-- Define common known file types -->
<extension
diff --git a/bundles/org.eclipse.team.core/schema/defaultFileModificationValidator.exsd b/bundles/org.eclipse.team.core/schema/defaultFileModificationValidator.exsd
new file mode 100644
index 000000000..fa92cdb49
--- /dev/null
+++ b/bundles/org.eclipse.team.core/schema/defaultFileModificationValidator.exsd
@@ -0,0 +1,103 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.team.core">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.team.core" id="defaultFileModificationValidator" name="Default File Modification Validator"/>
+ </appInfo>
+ <documentation>
+ This extension point is for external use only. It&apos;s purpose is to provide prompting for the overwriting of read-only resources using validateEdit on unshared projects.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="validator"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="validator">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ 3.1
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ Internal use only
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ Internal use only
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (c) 2004 IBM Corporation and others.
+All rights reserved. This program and the accompanying materials are made available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at &lt;a href=&quot;http://www.eclipse.org/legal/cpl-v10.html&quot;&gt;http://www.eclipse.org/legal/cpl-v10.html&lt;/a&gt;
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileModificationValidatorManager.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileModificationValidatorManager.java
index 7ad8a72c9..b211a8305 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileModificationValidatorManager.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileModificationValidatorManager.java
@@ -18,13 +18,13 @@ import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFileModificationValidator;
+import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.team.core.RepositoryProvider;
public class FileModificationValidatorManager implements IFileModificationValidator {
- private static final IFileModificationValidator DEFAULT_VALIDATOR =
- new DefaultFileModificationValidator();
+ private IFileModificationValidator defaultValidator;
/*
* @see IFileModificationValidator#validateEdit(IFile[], Object)
@@ -59,7 +59,7 @@ public class FileModificationValidatorManager implements IFileModificationValida
RepositoryProvider provider = (RepositoryProvider)providersIterator.next();
ArrayList filesList = (ArrayList)providersToFiles.get(provider);
IFile[] filesArray = (IFile[])filesList.toArray(new IFile[filesList.size()]);
- IFileModificationValidator validator = DEFAULT_VALIDATOR;
+ IFileModificationValidator validator = getDefaultValidator();
//if no provider or no validator use the default validator
if (provider != null) {
@@ -93,7 +93,7 @@ public class FileModificationValidatorManager implements IFileModificationValida
*/
public IStatus validateSave(IFile file) {
RepositoryProvider provider = RepositoryProvider.getProvider(file.getProject());
- IFileModificationValidator validator = DEFAULT_VALIDATOR;
+ IFileModificationValidator validator = getDefaultValidator();
//if no provider or no validator use the default validator
if (provider != null) {
@@ -103,4 +103,32 @@ public class FileModificationValidatorManager implements IFileModificationValida
return validator.validateSave(file);
}
+
+ private synchronized IFileModificationValidator getDefaultValidator() {
+ if (defaultValidator == null) {
+ loadDefaultValidator();
+ }
+ return defaultValidator;
+ }
+
+ private void loadDefaultValidator() {
+ defaultValidator = new DefaultFileModificationValidator();
+ IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(TeamPlugin.ID, TeamPlugin.DEFAULT_FILE_MODIFICATION_VALIDATOR_EXTENSION);
+ if (extension != null) {
+ IExtension[] extensions = extension.getExtensions();
+ if (extensions.length > 0) {
+ IConfigurationElement[] configElements = extensions[0].getConfigurationElements();
+ if (configElements.length > 0) {
+ try {
+ Object o = configElements[0].createExecutableExtension("class"); //$NON-NLS-1$
+ if (o instanceof IFileModificationValidator) {
+ defaultValidator = (IFileModificationValidator)o;
+ }
+ } catch (CoreException e) {
+ TeamPlugin.log(e);
+ }
+ }
+ }
+ }
+ }
}
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java
index 2404d63b7..a5fa77c7b 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java
@@ -44,8 +44,10 @@ final public class TeamPlugin extends Plugin {
public static final String IGNORE_EXTENSION = "ignore"; //$NON-NLS-1$
// The id of the project set extension point
public static final String PROJECT_SET_EXTENSION = "projectSets"; //$NON-NLS-1$
- // The id of the targets extension point
+ // The id of the repository extension point
public static final String REPOSITORY_EXTENSION = "repository"; //$NON-NLS-1$
+ // The id of the default file modification vaidator extension point
+ public static final String DEFAULT_FILE_MODIFICATION_VALIDATOR_EXTENSION = "defaultFileModificationValidator"; //$NON-NLS-1$
// The one and only plug-in instance
diff --git a/bundles/org.eclipse.team.ui/plugin.xml b/bundles/org.eclipse.team.ui/plugin.xml
index 7f4424df6..606205a53 100644
--- a/bundles/org.eclipse.team.ui/plugin.xml
+++ b/bundles/org.eclipse.team.ui/plugin.xml
@@ -282,5 +282,9 @@
id="org.eclipse.team.ui.ConfigureProject"/>
</actionSet>
</extension>
+ <extension
+ point="org.eclipse.team.core.defaultFileModificationValidator">
+ <validator class="org.eclipse.team.internal.ui.DefaultUIFileModificationValidator"/>
+ </extension>
</plugin>
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/DefaultUIFileModificationValidator.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/DefaultUIFileModificationValidator.java
new file mode 100644
index 000000000..712b8b010
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/DefaultUIFileModificationValidator.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ui;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.internal.core.DefaultFileModificationValidator;
+import org.eclipse.team.internal.ui.dialogs.DetailsDialog;
+
+/**
+ * Override the default file modification validator to prompt to
+ * make read-only files writtable
+ */
+public class DefaultUIFileModificationValidator extends DefaultFileModificationValidator {
+
+ public static class FileListDialog extends DetailsDialog {
+
+ private final IFile[] files;
+
+ public static boolean openQuestion(Shell shell, IFile[] files) {
+ FileListDialog dialog = new FileListDialog(shell, files);
+ int code = dialog.open();
+ return code == OK;
+ }
+
+ public FileListDialog(Shell parentShell, IFile[] files) {
+ super(parentShell, Policy.bind("DefaultUIFileModificationValidator.0")); //$NON-NLS-1$
+ this.files = files;
+ setImageKey(DLG_IMG_WARNING);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#createMainDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ protected void createMainDialogArea(Composite parent) {
+ createWrappingLabel(parent, Policy.bind("DefaultUIFileModificationValidator.1")); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#createDropDownDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ protected Composite createDropDownDialogArea(Composite parent) {
+ Composite composite = createComposite(parent);
+ createWrappingLabel(composite, Policy.bind("DefaultUIFileModificationValidator.2")); //$NON-NLS-1$
+ org.eclipse.swt.widgets.List fileList = new org.eclipse.swt.widgets.List(composite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ GridData data = new GridData ();
+ data.heightHint = 75;
+ data.horizontalAlignment = GridData.FILL;
+ data.grabExcessHorizontalSpace = true;
+ fileList.setLayoutData(data);
+ fileList.setFont(parent.getFont());
+ for (int i = 0; i < files.length; i++) {
+ fileList.add(files[i].getFullPath().toString());
+ }
+ return composite;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#updateEnablements()
+ */
+ protected void updateEnablements() {
+ // Nothing to do
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#includeCancelButton()
+ */
+ protected boolean includeCancelButton() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#includeOkButton()
+ */
+ protected boolean includeOkButton() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+ */
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
+ createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, true);
+ super.createButtonsForButtonBar(parent);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#buttonPressed(int)
+ */
+ protected void buttonPressed(int id) {
+ if (IDialogConstants.YES_ID == id)
+ okPressed();
+ else if (IDialogConstants.NO_ID == id)
+ cancelPressed();
+ else
+ super.buttonPressed(id);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.core.DefaultFileModificationValidator#validateEdit(org.eclipse.core.resources.IFile[], java.lang.Object)
+ */
+ public IStatus validateEdit(final IFile[] files, Object context) {
+ if (files.length > 0 && context != null && context instanceof Shell) {
+ final Shell shell = (Shell)context;
+ final boolean[] ok = new boolean[] { false };
+ if (files.length == 1) {
+ shell.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ ok[0] = MessageDialog.openQuestion(shell, Policy.bind("DefaultUIFileModificationValidator.3"), Policy.bind("DefaultUIFileModificationValidator.4", files[0].getFullPath().toString())); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ });
+ } else {
+ shell.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ ok[0] = FileListDialog.openQuestion(shell, files);
+ }
+ });
+ }
+ if (ok[0]) {
+ for (int i = 0; i < files.length; i++) {
+ IFile file = files[i];
+ file.setReadOnly(false);
+ };
+ };
+ }
+ return super.validateEdit(files, context);
+ }
+}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/dialogs/DetailsDialog.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/dialogs/DetailsDialog.java
index 2d124ef6f..0e9d97aa5 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/dialogs/DetailsDialog.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/dialogs/DetailsDialog.java
@@ -270,7 +270,6 @@ abstract public class DetailsDialog extends Dialog {
this.imageKey = imageKey;
}
- protected static final int LABEL_WIDTH_HINT = 400;
protected Label createWrappingLabel(Composite parent, String text) {
Label label = new Label(parent, SWT.LEFT | SWT.WRAP);
label.setText(text);
@@ -279,8 +278,9 @@ abstract public class DetailsDialog extends Dialog {
data.horizontalAlignment = GridData.FILL;
data.horizontalIndent = 0;
data.grabExcessHorizontalSpace = true;
- data.widthHint = LABEL_WIDTH_HINT;
+ data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
label.setLayoutData(data);
+ label.setFont(parent.getFont());
return label;
}
@@ -293,6 +293,7 @@ abstract public class DetailsDialog extends Dialog {
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ composite.setFont(parent.getFont());
return composite;
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties
index a7c46a790..b71bb05a9 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties
@@ -450,3 +450,8 @@ ConfigureProjectWizard.showAll=&Show All Wizards
ImportProjectSetMainPage.description=Creates projects from a previously exported project set list. A project set contains the names and locations of the projects and their contents are fetched from the given locations.
ExportProjectSetMainPage.description=Save a file containing the names and locations of the shared projects in the workspace.
+DefaultUIFileModificationValidator.0=Read-only Files Encountered
+DefaultUIFileModificationValidator.1=Some of the files being modified by the current operation are read-only. Do you wish to make them writable?
+DefaultUIFileModificationValidator.2=The following files are read-only:
+DefaultUIFileModificationValidator.3=Read-only File Encountered
+DefaultUIFileModificationValidator.4=File ''{0}'' is read-only. Do you wish to make it writable?

Back to the top