Commit 886f69d0 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

feat(BOSImport) Improve status dialog (#387)

* feat(BOSImport) Improve status dialog
parent 4b34a9cb
......@@ -47,6 +47,7 @@ public class IResourceImporter {
private Set<String> resourcesToOpen;
private final List<IRepositoryFileStore> fileStoresToOpen = new ArrayList<IRepositoryFileStore>();
private final List<IRepositoryFileStore> importedProcesses = new ArrayList<IRepositoryFileStore>();
private final List<IRepositoryFileStore> importedFileStore = new ArrayList<IRepositoryFileStore>();
private final List<String> failedProcesses = new ArrayList<String>();
public void run(final IContainer rootContainer, final IRepository repository, final IProgressMonitor monitor) throws ResourceImportException {
......@@ -148,6 +149,7 @@ public class IResourceImporter {
|| resourcesToOpen == null;
monitor.subTask(String.format("Importing %s in %s", filename, storeFolder.getName()));
final IRepositoryFileStore fileStore = store.importIResource(filename, child);
importedFileStore.add(fileStore);
if (filename.endsWith(".proc") && fileStore != null) {
importedProcesses.add(fileStore);
}
......@@ -166,4 +168,8 @@ public class IResourceImporter {
public void setResourcesToOpen(final Set<String> resourcesToOpen) {
this.resourcesToOpen = resourcesToOpen;
}
public List<IRepositoryFileStore> getImportedFileStore() {
return importedFileStore;
}
}
......@@ -49,4 +49,5 @@ public class BosArchiveImportStatus extends MultiStatus {
public boolean isOK() {
return super.isOK() || getSeverity() == INFO || getSeverity() == WARNING;
}
}
......@@ -16,15 +16,12 @@ package org.bonitasoft.studio.importer.bos.status;
import org.bonitasoft.studio.diagram.custom.repository.DiagramFileStore;
import org.bonitasoft.studio.diagram.custom.repository.DiagramRepositoryStore;
import org.bonitasoft.studio.importer.bos.i18n.Messages;
import org.bonitasoft.studio.importer.handler.DefaultImportStatusDialogHandler;
import org.bonitasoft.studio.importer.handler.ImportErrorMessageDialog;
import org.bonitasoft.studio.importer.handler.ImportStatusDialog;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.validation.common.operation.RunProcessesValidationOperation;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
/**
......@@ -41,8 +38,8 @@ public class BosImportStatusDialogHandler extends DefaultImportStatusDialogHandl
@Override
protected void openError(final Shell parentShell) {
final ImportErrorMessageDialog messageDialog = new ImportErrorMessageDialog(parentShell, getDialogMessage(importStatus),
importStatus instanceof BosArchiveImportStatus);
final ImportStatusDialog messageDialog = new ImportStatusDialog(parentShell, importStatus,
importStatus instanceof BosArchiveImportStatus && !((BosArchiveImportStatus) importStatus).getProcessesWithErrors().isEmpty());
final int result = messageDialog.open();
if (importStatus instanceof BosArchiveImportStatus && result == IDialogConstants.OPEN_ID) {
openDiagrams((BosArchiveImportStatus) importStatus);
......@@ -59,23 +56,4 @@ public class BosImportStatusDialogHandler extends DefaultImportStatusDialogHandl
RunProcessesValidationOperation.showValidationPart();
}
@Override
protected String createMessageForMultiStatus(final MultiStatus status) {
final StringBuilder sb = new StringBuilder();
if (status instanceof BosArchiveImportStatus) {
sb.append(Messages.processesWithErrorAfterImport);
sb.append(SWT.CR);
}
for (final IStatus childStatus : status.getChildren()) {
if (!childStatus.isOK()) {
sb.append(childStatus.getMessage());
sb.append(SWT.CR);
}
}
if (status instanceof BosArchiveImportStatus) {
sb.append(Messages.openDiagramWithErrors);
}
return sb.toString();
}
}
......@@ -60,6 +60,16 @@ public class ProcessValidationStatus extends Status {
return getSeverity() == IStatus.OK || getSeverity() == IStatus.INFO || getSeverity() == IStatus.WARNING;
}
/*
* (non-Javadoc)
* @see org.eclipse.core.runtime.Status#getSeverity()
*/
@Override
public int getSeverity() {
final int severity = super.getSeverity();
return severity == INFO ? OK : severity;
}
public AbstractProcess getProcess() {
return process;
}
......
......@@ -45,7 +45,9 @@ public class DiagramValidator implements BosImporterValidator {
new ValidationMarkerProvider()));
validationAction.addProcess(process);
validationAction.run(monitor);
statusBuilder.addStatus(process, validationAction.getStatus());
if(!validationAction.getStatus().isOK()){
statusBuilder.addStatus(process, validationAction.getStatus());
}
} catch (final ReadFileStoreException | InvocationTargetException | InterruptedException e) {
throw new ValidationException(e, "Failed to validate diagram content");
}
......
......@@ -16,4 +16,6 @@ ImportProcessButtonLabel=Import
importResultTitle=Import status
importSucessfulMessage=Import successfully completed.
openDiagram=Open diagrams
skipValidation=Skip validation >>
\ No newline at end of file
skipValidation=Skip validation >>
importStatusMsg=Problems has been detected in imported content.
copyToClipboard=Copy to clipboard
\ No newline at end of file
......@@ -16,9 +16,7 @@ package org.bonitasoft.studio.importer.handler;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
/**
......@@ -37,7 +35,8 @@ public class DefaultImportStatusDialogHandler implements ImportStatusDialogHandl
//Dot not display during tests
if (!FileActionDialog.getDisablePopup()) {
if (importStatus.isOK()) {
MessageDialog.openInformation(parentShell, org.bonitasoft.studio.importer.i18n.Messages.importResultTitle, getDialogMessage(importStatus));
MessageDialog.openInformation(parentShell, org.bonitasoft.studio.importer.i18n.Messages.importResultTitle,
org.bonitasoft.studio.importer.i18n.Messages.importSucessfulMessage);
} else {
openError(parentShell);
}
......@@ -45,29 +44,9 @@ public class DefaultImportStatusDialogHandler implements ImportStatusDialogHandl
}
protected void openError(final Shell parentShell) {
new ImportErrorMessageDialog(parentShell, getDialogMessage(importStatus),
new ImportStatusDialog(parentShell, importStatus,
false).open();
}
protected String getDialogMessage(final IStatus status) {
if (status.isOK()) {
return org.bonitasoft.studio.importer.i18n.Messages.importSucessfulMessage;
}
if (status instanceof MultiStatus) {
return createMessageForMultiStatus((MultiStatus) status);
}
return status.getMessage();
}
protected String createMessageForMultiStatus(final MultiStatus status) {
final StringBuilder sb = new StringBuilder();
for (final IStatus childStatus : status.getChildren()) {
if (!childStatus.isOK()) {
sb.append(childStatus.getMessage());
sb.append(SWT.CR);
}
}
return sb.toString();
}
}
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.importer.handler;
import org.bonitasoft.studio.importer.i18n.Messages;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
/**
* @author Romain Bioteau
*
*/
public class ImportErrorMessageDialog extends MessageDialog {
public ImportErrorMessageDialog(final Shell parentShell, final String dialogMessage, final boolean canOpen) {
super(parentShell, org.bonitasoft.studio.importer.i18n.Messages.importResultTitle, null, dialogMessage, WARNING,
getLabels(canOpen), 0);
}
protected static String[] getLabels(final boolean canOpen) {
if (canOpen) {
return new String[] { Messages.openDiagram, IDialogConstants.OK_LABEL };
}
return new String[] { IDialogConstants.OK_LABEL };
}
@Override
protected Button createButton(final Composite parent, final int id, final String label, final boolean defaultButton) {
if (Messages.openDiagram.equals(label)) {
return super.createButton(parent, IDialogConstants.OPEN_ID, label, defaultButton);
}
return super.createButton(parent, id, label, defaultButton);
}
}
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.importer.handler;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Lists.newArrayList;
import org.bonitasoft.studio.importer.i18n.Messages;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.jface.dialogs.Dialog;
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.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import com.google.common.base.Predicate;
public class ImportStatusDialog extends MessageDialog {
private final IStatus importStatus;
public ImportStatusDialog(final Shell parentShell, final IStatus importStatus, final boolean canOpen) {
super(parentShell, org.bonitasoft.studio.importer.i18n.Messages.importResultTitle, null, org.bonitasoft.studio.importer.i18n.Messages.importStatusMsg,
NONE,
getLabels(canOpen), 0);
this.importStatus = importStatus;
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#getInitialSize()
*/
@Override
protected Point getInitialSize() {
return getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
}
protected static String[] getLabels(final boolean canOpen) {
if (canOpen) {
return new String[] { Messages.openDiagram, IDialogConstants.OK_LABEL, Messages.copyToClipboard };
}
return new String[] { IDialogConstants.OK_LABEL, Messages.copyToClipboard };
}
@Override
protected Control createCustomArea(Composite parent) {
if (importStatus.isOK()) {
return super.createCustomArea(parent);
}
final TableViewer problemsViewer = new TableViewer(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
problemsViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).indent(0, 10).create());
problemsViewer.setContentProvider(ArrayContentProvider.getInstance());
problemsViewer.setLabelProvider(new LabelProvider() {
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
*/
@Override
public String getText(Object element) {
return ((IStatus) element).getMessage();
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
*/
@Override
public Image getImage(Object element) {
switch (((IStatus) element).getSeverity()) {
case IStatus.ERROR: return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
case IStatus.WARNING: return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
case IStatus.INFO: return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO);
default:
break;
}
return null;
}
});
if (importStatus instanceof MultiStatus) {
problemsViewer.setInput(newArrayList(filter(newArrayList(importStatus.getChildren()), notOk())));
}
return problemsViewer.getControl();
}
private Predicate<IStatus> notOk() {
return new Predicate<IStatus>() {
@Override
public boolean apply(IStatus status) {
return !status.isOK() || status.getSeverity() == IStatus.INFO;
}
};
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.dialogs.MessageDialog#buttonPressed(int)
*/
@Override
protected void buttonPressed(int buttonId) {
if (IDialogConstants.NO_ID != buttonId) {
super.buttonPressed(buttonId);
}
}
@Override
protected Button createButton(final Composite parent, final int id, final String label, final boolean defaultButton) {
if (Messages.openDiagram.equals(label)) {
return super.createButton(parent, IDialogConstants.OPEN_ID, label, defaultButton);
}
if (Messages.copyToClipboard.equals(label)) {
final Button copyButton = super.createButton(parent, IDialogConstants.NO_ID, label, defaultButton);
copyButton.addSelectionListener(new SelectionAdapter() {
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
final Clipboard cb = new Clipboard(Display.getDefault());
final TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[] { statusMessages() },
new Transfer[] { textTransfer });
}
});
return copyButton;
}
return super.createButton(parent, id, label, defaultButton);
}
protected String statusMessages() {
if (importStatus instanceof MultiStatus) {
return createMessageForMultiStatus((MultiStatus) importStatus);
}
return importStatus.getMessage();
}
protected String createMessageForMultiStatus(final MultiStatus status) {
final StringBuilder sb = new StringBuilder();
for (final IStatus childStatus : status.getChildren()) {
if (!childStatus.isOK()) {
sb.append(childStatus.getMessage());
sb.append(SWT.CR);
}
}
return sb.toString();
}
}
......@@ -44,5 +44,7 @@ public class Messages extends NLS {
public static String importResultTitle;
public static String openDiagram;
public static String skipValidation;
public static String importStatusMsg;
public static String copyToClipboard;
}
......@@ -79,18 +79,14 @@ public class BatchValidationOperation extends WorkspaceModifyOperation {
@Override
protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
Assert.isLegal(!diagramsToDiagramEditPart.isEmpty());
monitor.beginTask(Messages.validating, diagramsToDiagramEditPart.size());
buildEditPart();
validationMarkerProvider.clearMarkers(diagramsToDiagramEditPart);
for (final Entry<Diagram, DiagramEditPart> entry : diagramsToDiagramEditPart.entrySet()) {
final DiagramEditPart diagramEp = entry.getValue();
final Diagram diagram = entry.getKey();
if (diagramEp != null) {
if (!monitor.isCanceled()) {
monitor.subTask(subTaskName(diagramEp.resolveSemanticElement()));
monitor.setTaskName(subTaskName(diagramEp.resolveSemanticElement()));
final TransactionalEditingDomain txDomain = TransactionUtil.getEditingDomain(diagram);
runWithConstraints(txDomain, new Runnable() {
......@@ -99,6 +95,7 @@ public class BatchValidationOperation extends WorkspaceModifyOperation {
validate(diagramEp, diagram, monitor);
}
});
monitor.worked(1);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment