Author: fbricon
Date: 2011-11-17 08:51:29 -0500 (Thu, 17 Nov 2011)
New Revision: 36404
Added:
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/IMaterializeLibraryWarningFactory.java
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryWarningFactory.java
Modified:
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/Messages.java
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryDialog.java
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/messages.properties
Log:
JBIDE-9878 : Add warnings for when the Maven or JRE libraries are about to be
materialized
Modified:
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/Messages.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/Messages.java 2011-11-17
13:03:18 UTC (rev 36403)
+++
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/Messages.java 2011-11-17
13:51:29 UTC (rev 36404)
@@ -15,13 +15,21 @@
/**
*
* @author Fred Bricon
- *
+ *
*/
public class Messages extends NLS {
private static final String BUNDLE_NAME =
"org.jboss.tools.common.jdt.ui.messages"; //$NON-NLS-1$
-
+
public static String Materialize_Library;
-
+
+ public static String Maven_Configuration_Warning;
+
+ public static String Maven_Configuration_Dialog_Warning;
+
+ public static String Jre_Warning;
+
+ public static String Jre_Dialog_Warning;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Added:
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/IMaterializeLibraryWarningFactory.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/IMaterializeLibraryWarningFactory.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/IMaterializeLibraryWarningFactory.java 2011-11-17
13:51:29 UTC (rev 36404)
@@ -0,0 +1,36 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.common.jdt.ui.buildpath.dialog;
+
+import org.eclipse.jdt.core.IClasspathContainer;
+
+/**
+ * Warning message factory for classpath libraries to be materialized.
+ *
+ * @author Fred Bricon
+ *
+ */
+public interface IMaterializeLibraryWarningFactory {
+
+ /**
+ * Returns a simple warning message associated with the materialization of a classpath
library.
+ * @return a warning message or <code>null</code> if it doesn't apply.
+ */
+ String getWarning(IClasspathContainer classpathLibrary);
+
+ /**
+ * Returns a warning message associated with the materialization of a classpath library.
+ * This message is destined to be displayed in a dialog window.
+ * @return a warning message associated with the materialization of a classpath
library,
+ * or <code>null</code> if it doesn't apply.
+ */
+ String getDialogWarning(IClasspathContainer classpathLibrary);
+}
Modified:
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryDialog.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryDialog.java 2011-11-17
13:03:18 UTC (rev 36403)
+++
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryDialog.java 2011-11-17
13:51:29 UTC (rev 36404)
@@ -26,7 +26,12 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
@@ -37,12 +42,14 @@
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -82,7 +89,13 @@
private Button keepSourceBtn;
private boolean keepSources;
+
+ private IMaterializeLibraryWarningFactory warningfactory;
+ private Label warningImg;
+
+ private Label warningLabel;
+
public MaterializeLibraryDialog(Shell shell, IProject project, IClasspathContainer
containerToMaterialize, String defaultLib) {
super(shell);
setShellStyle(super.getShellStyle() | SWT.RESIZE | SWT.MODELESS);
@@ -90,6 +103,7 @@
IPath folderPath = project.getFullPath().append(defaultLib);
libFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(folderPath);
this.containerToMaterialize = containerToMaterialize;
+ warningfactory = new MaterializeLibraryWarningFactory();
initClasspathEntryPaths();
}
@@ -132,10 +146,14 @@
layout.marginLeft = 12;
container.setLayout(layout);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ String message = NLS.bind("Copy selected jars from {0} to the destination
folder.",libName);
+ String warning = warningfactory.getWarning(containerToMaterialize);
+ if (warning != null) {
+ displayWarning(container, warning);
+ }
+ setMessage(message);
- setMessage("Copy selected jars from " + libName
- + " to the destination folder.");
-
Label libFolderLabel = new Label(container, SWT.NONE);
libFolderLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
false, 1, 1));
@@ -159,6 +177,21 @@
return area;
}
+
+ private void displayWarning(Composite container, String warning) {
+ Composite composite = new Composite(container, SWT.NONE);
+ GridDataFactory.fillDefaults().align(SWT.LEFT,SWT.CENTER).span(3,1).applyTo(composite);
+ GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
+ warningImg = new Label(composite, SWT.CENTER);
+ warningImg.setImage(JFaceResources.getImage(DLG_IMG_MESSAGE_WARNING));
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(warningImg);
+ warningLabel = new Label(composite, SWT.NONE);
+ warningLabel.setText(warning);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(warningLabel);
+ }
+
+
+
private void addSelectFolderButton(Composite container) {
Button button = new Button(container, SWT.NONE);
@@ -201,7 +234,7 @@
gd.widthHint = 550;
classpathEntriesViewer = CheckboxTableViewer.newCheckList(container,
- SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
+ SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION );
Table table = classpathEntriesViewer.getTable();
table.setFocus();
table.setLayoutData(gd);
@@ -285,6 +318,18 @@
if (!validate()) {
return;
}
+
+ String dialogWarning = warningfactory.getDialogWarning(containerToMaterialize);
+ if (dialogWarning != null) {
+ String[] buttonLabels = new String[] { IDialogConstants.OK_LABEL,
+ IDialogConstants.CANCEL_LABEL };
+
+ MessageDialog dialog = new MessageDialog(getShell(), getShell().getText(), null,
dialogWarning,
+ MessageDialog.WARNING, buttonLabels, 0);
+ if (dialog.open() == CANCEL) {
+ return;
+ }
+ }
libFolder = getLibFolderFromText(libfolderText.getText());
keepSources = keepSourceBtn.getSelection();
super.okPressed();
Added:
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryWarningFactory.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryWarningFactory.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryWarningFactory.java 2011-11-17
13:51:29 UTC (rev 36404)
@@ -0,0 +1,53 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.common.jdt.ui.buildpath.dialog;
+
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.jdt.ui.Messages;
+
+public class MaterializeLibraryWarningFactory implements
IMaterializeLibraryWarningFactory {
+
+ @Override
+ public String getWarning(IClasspathContainer classpathLibrary) {
+ if (isMavenLibrary(classpathLibrary)) {
+ return Messages.Maven_Configuration_Warning;
+ } else if (isJreLibrary(classpathLibrary)) {
+ return NLS.bind(Messages.Jre_Warning, classpathLibrary.getDescription());
+ }
+ return null;
+ }
+
+ @Override
+ public String getDialogWarning(IClasspathContainer classpathLibrary) {
+ if (isMavenLibrary(classpathLibrary)) {
+ return Messages.Maven_Configuration_Dialog_Warning;
+ } else if (isJreLibrary(classpathLibrary)) {
+ return NLS.bind(Messages.Jre_Dialog_Warning, classpathLibrary.getDescription());
+ }
+ return null;
+ }
+
+ private boolean isJreLibrary(IClasspathContainer classpathLibrary) {
+ return applies(classpathLibrary, "org.eclipse.jdt.launching.JRE_CONTAINER");
+ }
+
+ private boolean isMavenLibrary(IClasspathContainer classpathLibrary) {
+ return applies(classpathLibrary,
"org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER");
+ }
+
+ private boolean applies(IClasspathContainer classpathLibrary, String libPrefix) {
+ return classpathLibrary != null
+ && classpathLibrary.getPath() != null
+ && classpathLibrary.getPath().toPortableString().startsWith(libPrefix);
+ }
+
+}
Modified:
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/messages.properties
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/messages.properties 2011-11-17
13:03:18 UTC (rev 36403)
+++
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/messages.properties 2011-11-17
13:51:29 UTC (rev 36404)
@@ -1,3 +1,7 @@
Materialize_Library=Materialize Library
+
+Maven_Configuration_Warning =This will also remove the Maven configuration from this
project.
+Maven_Configuration_Dialog_Warning = This will also remove the Maven configuration from
this project.\nThis operation cannot be undone, are you sure ?
+Jre_Warning = Materializing {0} might have unexpected consequences and is not
recommended.
+Jre_Dialog_Warning = Materializing {0} might have unexpected consequences and is not
recommended. Are you sure?
-