Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormzhu2011-05-06 06:05:18 +0000
committermzhu2011-05-06 06:05:18 +0000
commit7a4b6083659d0ecd17473acf3229b5581b096807 (patch)
treea67f7d6f9a6480fc9b6218e17174be2c93d27f06 /bundles/org.eclipse.equinox.p2.ui.importexport
parentaf75978b27f83dc20bd7646c2429aa4fc6a6c0ad (diff)
downloadrt.equinox.p2-7a4b6083659d0ecd17473acf3229b5581b096807.tar.gz
rt.equinox.p2-7a4b6083659d0ecd17473acf3229b5581b096807.tar.xz
rt.equinox.p2-7a4b6083659d0ecd17473acf3229b5581b096807.zip
Fixed bugzilla 343548.
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.ui.importexport')
-rwxr-xr-xbundles/org.eclipse.equinox.p2.ui.importexport/META-INF/MANIFEST.MF3
-rwxr-xr-xbundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/Messages.java2
-rwxr-xr-xbundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/messages.properties6
-rwxr-xr-xbundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/AbstractWizard.java6
-rwxr-xr-xbundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage.java60
-rw-r--r--bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/StyledErrorDialog.java173
6 files changed, 214 insertions, 36 deletions
diff --git a/bundles/org.eclipse.equinox.p2.ui.importexport/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.ui.importexport/META-INF/MANIFEST.MF
index 2df82a1c5..aca95f575 100755
--- a/bundles/org.eclipse.equinox.p2.ui.importexport/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.ui.importexport/META-INF/MANIFEST.MF
@@ -8,7 +8,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.equinox.p2.ui,
org.eclipse.equinox.p2.extensionlocation,
- org.eclipse.equinox.p2.metadata;bundle-version="2.1.0"
+ org.eclipse.equinox.p2.metadata;bundle-version="2.1.0",
+ org.eclipse.ui.forms;bundle-version="3.5.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5,
J2SE-1.4,
CDC-1.1/Foundation-1.1
diff --git a/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/Messages.java b/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/Messages.java
index 170127598..8b94349cb 100755
--- a/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/Messages.java
+++ b/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/Messages.java
@@ -17,6 +17,7 @@ public class Messages extends NLS {
public static String Column_Name;
public static String Column_Version;
public static String ExportPage_Title;
+ public static String ExportPage_TryAgainQuestion;
public static String ExportPage_Description;
public static String ExportPage_Label;
public static String ExportPage_DEST_ERRORMESSAGE;
@@ -24,6 +25,7 @@ public class Messages extends NLS {
public static String ExportPage_EXPORT_WARNING;
public static String ExportPage_Fail;
public static String ExportPage_FILEDIALOG_TITLE;
+ public static String ExportPage_FixSuggestion;
public static String EXTENSION_ALL;
public static String EXTENSION_ALL_NAME;
public static String EXTENSION_p2F_NAME;
diff --git a/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/messages.properties b/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/messages.properties
index 48f83f6b9..c8b409626 100755
--- a/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/messages.properties
+++ b/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/messages.properties
@@ -12,6 +12,7 @@ Column_Id=Id
Column_Name=Name
Column_Version=Version
ExportPage_Title=Export software configuration
+ExportPage_TryAgainQuestion=<p>Do you want to try again?</p></form>
ExportPage_Description=Export a list of installed software and their repositories to the local file system.
ExportPage_Label=Select the software items to export:
EXTENSION_ALL=*.*
@@ -22,10 +23,11 @@ Page_BUTTON_BROWSER=Browse...
ExportPage_DEST_ERRORMESSAGE=p2 installation file is not set, or is not a normal file.
ExportPage_ERROR_CONFIG=Eclipse p2 is not properly configured.
ExportPage_EXPORT_WARNING=Can't find repository for the following elements. Please check the network connection.\n
-ExportPage_Fail=Selected installed software failed to be export. See problems below:\n
+ExportPage_Fail=<form><p>Selected installed software failed to be export. See problems below:<br/></p>
ExportPage_FILEDIALOG_TITLE=Export the list of installed software to file
+ExportPage_FixSuggestion=<p>Try to enable the software sites in the <a href="pref://org.eclipse.equinox.internal.p2.ui.sdk.SitesPreferencePage">preference page</a>.</p>
ExportPage_LABEL_EXPORTFILE=To p2 exported file:
-ExportPage_SuccessWithProblems=The export partially succeeded. The following elements failed to be exported:\n
+ExportPage_SuccessWithProblems=<form><p>The export partially succeeded. The following elements failed to be exported:<br/></p>
ExportWizard_WizardTitle=Export
PAGE_NOINSTALLTION_ERROR=Nothing is selected.
ImportPage_DESCRIPTION=Install the software mentioned in p2f description file.
diff --git a/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/AbstractWizard.java b/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/AbstractWizard.java
index 501170c7f..46e7c4893 100755
--- a/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/AbstractWizard.java
+++ b/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/AbstractWizard.java
@@ -28,9 +28,11 @@ public abstract class AbstractWizard extends Wizard {
public boolean performFinish() {
try {
mainPage.doFinish();
+ } catch (InterruptedException e) {
+ // cancelled by user
+ return false;
} catch (Exception e) {
- Platform.getLog(Platform.getBundle(Constants.Bundle_ID)).log(
- new Status(IStatus.ERROR, Constants.Bundle_ID, e.getMessage(), e));
+ Platform.getLog(Platform.getBundle(Constants.Bundle_ID)).log(new Status(IStatus.ERROR, Constants.Bundle_ID, e.getMessage(), e));
MessageBox messageBox = new MessageBox(this.getShell(), SWT.ICON_ERROR);
messageBox.setMessage(e.getMessage() == null ? "Unknown error" : e.getMessage()); //$NON-NLS-1$
messageBox.open();
diff --git a/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage.java b/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage.java
index 2ce89a9d6..9e65f197e 100755
--- a/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage.java
+++ b/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/ExportPage.java
@@ -11,17 +11,16 @@
package org.eclipse.equinox.internal.p2.importexport.internal.wizard;
import java.io.*;
-import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.importexport.internal.Messages;
import org.eclipse.equinox.internal.p2.ui.ProvUI;
import org.eclipse.equinox.internal.p2.ui.model.ProfileElement;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.*;
+import org.eclipse.ui.PlatformUI;
public class ExportPage extends AbstractPage {
@@ -35,9 +34,9 @@ public class ExportPage extends AbstractPage {
protected void createContents(Composite composite) {
Label label = new Label(composite, SWT.NONE);
label.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
- if(getSelfProfile() == null){
+ if (getSelfProfile() == null) {
label.setText(Messages.ExportPage_ERROR_CONFIG);
- }else {
+ } else {
label.setText(Messages.ExportPage_Label);
createInstallationTable(composite);
@@ -48,67 +47,68 @@ public class ExportPage extends AbstractPage {
@Override
public void doFinish() throws Exception {
finishException = null;
- if(viewer == null)
+ if (viewer == null)
return;
final Object[] checked = viewer.getCheckedElements();
OutputStream stream = null;
try {
File target = new File(ExportPage.this.destinationNameField.getText());
- if(!target.exists())
+ if (!target.exists())
target.createNewFile();
stream = new BufferedOutputStream(new FileOutputStream(target));
final OutputStream out = stream;
getContainer().run(true, true, new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) throws InvocationTargetException,
- InterruptedException {
+ public void run(IProgressMonitor monitor) throws InterruptedException {
try {
IInstallableUnit[] units = new IInstallableUnit[checked.length];
- for(int i = 0; i < units.length; i++)
+ for (int i = 0; i < units.length; i++)
units[i] = ProvUI.getAdapter(checked[i], IInstallableUnit.class);
IStatus status = importexportService.exportP2F(out, units, monitor);
if (status.isMultiStatus()) {
final StringBuilder sb = new StringBuilder();
- boolean info = true;
for (IStatus child : status.getChildren()) {
if (child.isMultiStatus()) {
for (IStatus grandchild : child.getChildren())
- sb.append(grandchild.getMessage()).append("\n"); //$NON-NLS-1$
+ sb.append("<li>").append(grandchild.getMessage()).append("</li>"); //$NON-NLS-1$ //$NON-NLS-2$
} else if (child.isOK())
sb.insert(0, Messages.ExportPage_SuccessWithProblems);
- else {
- info = false;
- sb.insert(0, Messages.ExportPage_Fail);
- sb.append(status.getMessage());
- }
+ else {
+ sb.insert(0, Messages.ExportPage_Fail);
+ sb.append(status.getMessage());
+ }
}
- final boolean isInfo = info;
- Display.getDefault().asyncExec(new Runnable() {
+ sb.append(Messages.ExportPage_FixSuggestion);
+ sb.append(Messages.ExportPage_TryAgainQuestion);
+ Runnable runnable = new Runnable() {
+
public void run() {
String title = Messages.ExportPage_Title;
- if (isInfo == true)
- MessageDialog.openInformation(getShell(), title, sb.toString());
- else
- MessageDialog.openWarning(getShell(), title, sb.toString());
+ tryAgain = StyledErrorDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, sb.toString());
}
- });
+ };
+ Display.getDefault().syncExec(runnable);
+ if (tryAgain)
+ throw new OperationCanceledException("User chosed try again."); //$NON-NLS-1$
}
} catch (OperationCanceledException e) {
throw new InterruptedException(e.getMessage());
+ } catch (Exception e) {
+ e.printStackTrace();
}
- }
+ }
+
+ boolean tryAgain = false;
});
- } catch (InterruptedException e) {
- // do nothing for cancelled by users
} finally {
- if(stream != null) {
+ if (stream != null) {
try {
stream.close();
} catch (IOException e) {
// do nothing
}
}
- if(finishException != null)
+ if (finishException != null)
throw finishException;
}
}
@@ -120,12 +120,10 @@ public class ExportPage extends AbstractPage {
@Override
protected Object getInput() {
- // return importexportService.getRootIUs();
ProfileElement element = new ProfileElement(null, getSelfProfile().getProfileId());
return element;
}
-
@Override
protected String getInvalidDestinationMessage() {
return Messages.ExportPage_DEST_ERRORMESSAGE;
@@ -133,7 +131,7 @@ public class ExportPage extends AbstractPage {
@Override
protected void giveFocusToDestination() {
- if(viewer != null)
+ if (viewer != null)
viewer.getControl().setFocus();
}
diff --git a/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/StyledErrorDialog.java b/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/StyledErrorDialog.java
new file mode 100644
index 000000000..1c6782bc6
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.ui.importexport/src/org/eclipse/equinox/internal/p2/importexport/internal/wizard/StyledErrorDialog.java
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * Copyright (c) 2011 WindRiver Corporation 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:
+ * WindRiver Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.internal.p2.importexport.internal.wizard;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.core.commands.*;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.importexport.internal.Constants;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.accessibility.AccessibleAdapter;
+import org.eclipse.swt.accessibility.AccessibleEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.ui.IWorkbenchCommandConstants;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.forms.events.HyperlinkAdapter;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
+import org.eclipse.ui.forms.widgets.FormText;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+public class StyledErrorDialog extends MessageDialog {
+
+ public static boolean openQuestion(Shell parent, String title, String message) {
+ return open(QUESTION, parent, title, message, SWT.NONE);
+ }
+
+ public static void openInformation(Shell parent, String title, String message) {
+ open(INFORMATION, parent, title, message, SWT.NONE);
+ }
+
+ public static void openWarning(Shell parent, String title, String message) {
+ open(WARNING, parent, title, message, SWT.NONE);
+ }
+
+ public static boolean open(int kind, Shell parent, String title, String message, int style) {
+ StyledErrorDialog dialog = new StyledErrorDialog(parent, title, null, message, kind, getButtonLabels(kind), 0);
+ int style2 = style & SWT.SHEET;
+ dialog.setShellStyle(dialog.getShellStyle() | style2);
+ return dialog.open() == 0;
+ }
+
+ /**
+ * @param kind
+ */
+ static String[] getButtonLabels(int kind) {
+ String[] dialogButtonLabels;
+ switch (kind) {
+ case ERROR :
+ case INFORMATION :
+ case WARNING : {
+ dialogButtonLabels = new String[] {IDialogConstants.OK_LABEL};
+ break;
+ }
+ case CONFIRM : {
+ dialogButtonLabels = new String[] {IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL};
+ break;
+ }
+ case QUESTION : {
+ dialogButtonLabels = new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL};
+ break;
+ }
+ case QUESTION_WITH_CANCEL : {
+ dialogButtonLabels = new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL};
+ break;
+ }
+ default : {
+ throw new IllegalArgumentException("Illegal value for kind in MessageDialog.open()"); //$NON-NLS-1$
+ }
+ }
+ return dialogButtonLabels;
+ }
+
+ public StyledErrorDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int imageType, String[] buttonLabels, int defaultIndex) {
+ super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, imageType, buttonLabels, defaultIndex);
+ }
+
+ @Override
+ protected Control createMessageArea(Composite composite) {
+ // create composite
+ // create image
+ Image image = getImage();
+ if (image != null) {
+ imageLabel = new Label(composite, SWT.NULL);
+ image.setBackground(imageLabel.getBackground());
+ imageLabel.setImage(image);
+ addAccessibleListeners(imageLabel, image);
+ GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING).applyTo(imageLabel);
+ }
+ // create message
+ if (message != null) {
+ FormToolkit toolkit = new FormToolkit(Display.getDefault());
+ Composite toolkitComp = toolkit.createComposite(composite);
+ toolkitComp.setLayout(new FillLayout(SWT.HORIZONTAL | SWT.VERTICAL));
+ FormText text = toolkit.createFormText(toolkitComp, false);
+ text.setText(message, true, true);
+ text.setBackground(composite.getBackground());
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).hint(convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), SWT.DEFAULT).applyTo(toolkitComp);
+ text.addHyperlinkListener(new HyperlinkAdapter() {
+ public void linkActivated(HyperlinkEvent event) {
+ try {
+ URI uri = URI.create((String) event.data);
+ if ("pref".equals(uri.getScheme())) { //$NON-NLS-1$
+ Map<String, String> para = new HashMap<String, String>();
+ para.put(IWorkbenchCommandConstants.WINDOW_PREFERENCES_PARM_PAGEID, uri.getAuthority());
+ Command prefCommand = ((ICommandService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(ICommandService.class)).getCommand(IWorkbenchCommandConstants.WINDOW_PREFERENCES);
+ prefCommand.executeWithChecks(new ExecutionEvent(prefCommand, para, null, null));
+ }
+ } catch (ExecutionException e) {
+ Platform.getLog(Platform.getBundle(Constants.Bundle_ID)).log(new Status(IStatus.ERROR, Constants.Bundle_ID, e.getMessage(), e));
+ } catch (NotDefinedException e) {
+ Platform.getLog(Platform.getBundle(Constants.Bundle_ID)).log(new Status(IStatus.ERROR, Constants.Bundle_ID, e.getMessage(), e));
+ } catch (NotEnabledException e) {
+ Platform.getLog(Platform.getBundle(Constants.Bundle_ID)).log(new Status(IStatus.ERROR, Constants.Bundle_ID, e.getMessage(), e));
+ } catch (NotHandledException e) {
+ Platform.getLog(Platform.getBundle(Constants.Bundle_ID)).log(new Status(IStatus.ERROR, Constants.Bundle_ID, e.getMessage(), e));
+ }
+ }
+ });
+ }
+ return composite;
+ }
+
+ private void addAccessibleListeners(Label label, final Image image) {
+ label.getAccessible().addAccessibleListener(new AccessibleAdapter() {
+ @Override
+ public void getName(AccessibleEvent event) {
+ final String accessibleMessage = getAccessibleMessageFor(image);
+ if (accessibleMessage == null) {
+ return;
+ }
+ event.result = accessibleMessage;
+ }
+ });
+ }
+
+ private String getAccessibleMessageFor(Image image) {
+ if (image.equals(getErrorImage())) {
+ return JFaceResources.getString("error");//$NON-NLS-1$
+ }
+
+ if (image.equals(getWarningImage())) {
+ return JFaceResources.getString("warning");//$NON-NLS-1$
+ }
+
+ if (image.equals(getInfoImage())) {
+ return JFaceResources.getString("info");//$NON-NLS-1$
+ }
+
+ if (image.equals(getQuestionImage())) {
+ return JFaceResources.getString("question"); //$NON-NLS-1$
+ }
+
+ return null;
+ }
+
+}

Back to the top