diff options
Diffstat (limited to 'plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse')
4 files changed, 171 insertions, 55 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/AbstractInsertImportInNattableManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/AbstractInsertImportInNattableManager.java index af5d5796fc1..babd488f9f9 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/AbstractInsertImportInNattableManager.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/AbstractInsertImportInNattableManager.java @@ -91,6 +91,9 @@ public abstract class AbstractInsertImportInNattableManager extends AbstractPast IStatus resultStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.InsertInNattableManager_InsertNotYetManaged); PasteEnablementStatus pasteStatus = null; + + int maxDepth = Integer.MAX_VALUE; + // Check if the paste configuration is needed for the paste action pasteStatus = findPasteModeFromTableConfiguration(this.tableManager); if (PasteModeEnumeration.PASTE_NO_CONFIGURATION != pasteStatus.getPasteMode() && PasteModeEnumeration.CANT_PASTE != pasteStatus.getPasteMode()) { @@ -114,7 +117,7 @@ public abstract class AbstractInsertImportInNattableManager extends AbstractPast resultStatus = createCantInsertStatus(pasteStatus); break; case PASTE_EOBJECT_ROW: - resultStatus = insertRow(this.tableManager, pasteStatus, pasteHelper); + resultStatus = insertRow(this.tableManager, pasteStatus, pasteHelper, maxDepth); break; case PASTE_EOBJECT_COLUMN: case PASTE_EOBJECT_ROW_OR_COLUMN: @@ -164,17 +167,19 @@ public abstract class AbstractInsertImportInNattableManager extends AbstractPast * the paste status * @param pasteHelper * the paste helper + * @param maxDepth + * The maximum depth to check. * @return * <code>true</code> if the paste can be done */ - private IStatus insertRow(final INattableModelManager manager, final PasteEnablementStatus pasteStatus, final CSVPasteHelper pasteHelper) { + private IStatus insertRow(final INattableModelManager manager, final PasteEnablementStatus pasteStatus, final CSVPasteHelper pasteHelper, final int maxDepth) { IStatus resultStatus = Status.OK_STATUS; if (TableHelper.isTreeTable(manager)) { if (null != tableSelectionWrapper) { resultStatus = insertTreeRows(manager, pasteStatus, pasteHelper, tableSelectionWrapper); } else { - resultStatus = insertTreeRows(manager, pasteStatus, pasteHelper); + resultStatus = insertTreeRows(manager, pasteStatus, pasteHelper, maxDepth); } } else { if (null != tableSelectionWrapper) { @@ -217,12 +222,12 @@ public abstract class AbstractInsertImportInNattableManager extends AbstractPast * The paste status. * @param pasteHelper * The paste helper. - * @param tableSelectionWrapper - * The current selection. + * @param maxDepth + * The maximum depth to check. * @return The status of the paste. */ - private IStatus insertTreeRows(final INattableModelManager manager, final PasteEnablementStatus pasteStatus, final CSVPasteHelper pasteHelper) { - IStatus status = checkTreeTableConfiguration(manager); + private IStatus insertTreeRows(final INattableModelManager manager, final PasteEnablementStatus pasteStatus, final CSVPasteHelper pasteHelper, final int maxDepth) { + IStatus status = checkTreeTableConfiguration(manager, maxDepth); if (status.isOK()) { status = insertTree(manager, pasteStatus, useProgressMonitorDialog, createReader(), null, getDataSize()); } diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/AbstractPasteImportInNattableManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/AbstractPasteImportInNattableManager.java index a9dc9833105..c93499d4854 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/AbstractPasteImportInNattableManager.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/AbstractPasteImportInNattableManager.java @@ -133,6 +133,9 @@ public abstract class AbstractPasteImportInNattableManager extends AbstractPaste IStatus resultStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.AbstractPasteImportInNattableManager_PasteNotYetManaged); PasteEnablementStatus pasteStatus = null; + + int maxDepth = Integer.MAX_VALUE; + // Check if the paste configuration is needed for the paste action boolean useElse = true; if (!isNeededPasteConfiguration()) { @@ -166,6 +169,9 @@ public abstract class AbstractPasteImportInNattableManager extends AbstractPaste } if (useElse) { + if(TableHelper.isTreeTable(tableManager)){ + maxDepth = PasteHelperUtils.getMaxDepthToPaste(tableManager, pasteHelper, createReader()); + } pasteStatus = findPasteModeFromTableConfiguration(this.tableManager); if (pasteStatus.getPasteMode() == PasteModeEnumeration.PASTE_EOBJECT_ROW_OR_COLUMN) { final boolean value = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), PasteImportStatusDialog.DIALOG_TITLE, Messages.AbstractPasteImportInsertInNattableManager_WhatAreYouPasting); @@ -186,7 +192,7 @@ public abstract class AbstractPasteImportInNattableManager extends AbstractPaste resultStatus = createCantPasteStatus(pasteStatus); break; case PASTE_EOBJECT_ROW: - resultStatus = pasteRow(this.tableManager, pasteStatus, pasteHelper); + resultStatus = pasteRow(this.tableManager, pasteStatus, pasteHelper, maxDepth); break; case PASTE_EOBJECT_COLUMN: resultStatus = pasteColumn(this.tableManager, pasteStatus, pasteHelper); @@ -276,17 +282,19 @@ public abstract class AbstractPasteImportInNattableManager extends AbstractPaste * the paste status * @param pasteHelper * the paste helper + * @param maxDepth + * The maximum depth to check. * @return * <code>true</code> if the paste can be done */ - private IStatus pasteRow(final INattableModelManager manager, final PasteEnablementStatus pasteStatus, final CSVPasteHelper pasteHelper) { + private IStatus pasteRow(final INattableModelManager manager, final PasteEnablementStatus pasteStatus, final CSVPasteHelper pasteHelper, final int maxDepth) { IStatus resultStatus = Status.OK_STATUS; if (TableHelper.isTreeTable(manager)) { if (null != tableSelectionWrapper) { resultStatus = pasteTreeRows(manager, pasteStatus, pasteHelper, tableSelectionWrapper); } else { - resultStatus = pasteTreeRows(manager, pasteStatus, pasteHelper); + resultStatus = pasteTreeRows(manager, pasteStatus, pasteHelper, maxDepth); } } else { if (null != tableSelectionWrapper) { @@ -331,10 +339,12 @@ public abstract class AbstractPasteImportInNattableManager extends AbstractPaste * The paste helper. * @param tableSelectionWrapper * The current selection. + * @param maxDepth + * The maximum depth to check. * @return The status of the paste. */ - private IStatus pasteTreeRows(final INattableModelManager manager, final PasteEnablementStatus pasteStatus, final CSVPasteHelper pasteHelper) { - IStatus status = checkTreeTableConfiguration(manager); + private IStatus pasteTreeRows(final INattableModelManager manager, final PasteEnablementStatus pasteStatus, final CSVPasteHelper pasteHelper, final int maxDepth) { + IStatus status = checkTreeTableConfiguration(manager, maxDepth); if (status.isOK()) { status = pasteTree(manager, pasteStatus, useProgressMonitorDialog, createReader(), null, getDataSize()); } diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/AbstractPasteImportInsertInNattableManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/AbstractPasteImportInsertInNattableManager.java index 33605280376..b8dcbec2a6f 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/AbstractPasteImportInsertInNattableManager.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/AbstractPasteImportInsertInNattableManager.java @@ -464,55 +464,61 @@ public abstract class AbstractPasteImportInsertInNattableManager { * * @param manager * The nattable model manager. + * @param maxDepth The maximum depth to check. * @return The status of the check. */ - protected IStatus checkTreeTableConfiguration(final INattableModelManager manager) { + protected IStatus checkTreeTableConfiguration(final INattableModelManager manager, final int maxDepth) { IStatus status = Status.OK_STATUS; // we check than there is only one categories by hidden depth final List<Integer> hiddenCategories = StyleUtils.getHiddenDepths(manager); for (final Integer current : hiddenCategories) { - final int size = FillingConfigurationUtils.getAllTreeFillingConfigurationForDepth(manager.getTable(), current.intValue()).size(); - if (size > 1) { - status = new PapyrusNattableStatus(IPapyrusNattableStatus.PASTE_CONFIGURATiON_ERROR, Activator.PLUGIN_ID, PasteSeverityCode.PASTE_ERROR__MORE_THAN_ONE_CATEGORY_FOR_A_HIDDEN_DEPTH, - NLS.bind(Messages.AbstractPasteImportInsertInNattableManager_YouHaveMoreThan1Category, current.intValue()), null); + if(current <= maxDepth){ + final int size = FillingConfigurationUtils.getAllTreeFillingConfigurationForDepth(manager.getTable(), current.intValue()).size(); + if (size > 1) { + status = new PapyrusNattableStatus(IPapyrusNattableStatus.PASTE_CONFIGURATiON_ERROR, Activator.PLUGIN_ID, PasteSeverityCode.PASTE_ERROR__MORE_THAN_ONE_CATEGORY_FOR_A_HIDDEN_DEPTH, + NLS.bind(Messages.AbstractPasteImportInsertInNattableManager_YouHaveMoreThan1Category, current.intValue()), null); + } } } if (status.isOK()) { for (final TreeFillingConfiguration current : FillingConfigurationUtils.getAllTreeFillingConfiguration(manager.getTable())) { - final PasteEObjectConfiguration conf = current.getPasteConfiguration(); - if (conf == null) { - // TODO : add detail of the error in message - status = new PapyrusNattableStatus(IPapyrusNattableStatus.PASTE_CONFIGURATiON_ERROR, Activator.PLUGIN_ID, PasteSeverityCode.PASTE_ERROR__NO_PASTE_CONFIGURATION, - Messages.AbstractPasteImportInsertInNattableManager_ThereIsNoPasteConfgurationForATreeFillingConfiguration, - null); - } else { - - final String elementTypeId = conf.getPastedElementId(); - if (elementTypeId == null || elementTypeId.isEmpty()) { - status = new PapyrusNattableStatus(IPapyrusNattableStatus.PASTE_CONFIGURATiON_ERROR, Activator.PLUGIN_ID, PasteSeverityCode.PASTE_ERROR__NO_ELEMENT_TYPE_IN_PASTE_CONFIGURATION, - Messages.AbstractPasteImportInsertInNattableManager_ThereIsNoElementIdDefinedInThePasteConfiguration, null); - } else if (!ElementTypeUtils.getAllExistingElementTypesIds().contains(elementTypeId)) { - status = new PapyrusNattableStatus(IPapyrusNattableStatus.PASTE_CONFIGURATiON_ERROR, Activator.PLUGIN_ID, PasteSeverityCode.PASTE_ERROR__UNKNOWN_ELEMENT_TYPE, - String.format(Messages.AbstractPasteImportInsertInNattableManager_TheElementTypeIsUnknown, elementTypeId), null); - } - - - if (status.isOK()) { - final EStructuralFeature feature = conf.getPasteElementContainementFeature(); - if (feature == null) { - final IAxis axis = current.getAxisUsedAsAxisProvider(); - final NatTable natTable = manager.getAdapter(NatTable.class); - final LabelProviderContextElementWrapper wrapper = new LabelProviderContextElementWrapper(); - wrapper.setObject(axis); - wrapper.setConfigRegistry(natTable.getConfigRegistry()); - final LabelProviderService serv = natTable.getConfigRegistry().getConfigAttribute(NattableConfigAttributes.LABEL_PROVIDER_SERVICE_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.LABEL_PROVIDER_SERVICE_ID); - ILabelProvider p = serv.getLabelProvider(wrapper); - p = serv.getLabelProvider(Constants.HEADER_LABEL_PROVIDER_CONTEXT); - final String categoryName = p.getText(axis); - status = new PapyrusNattableStatus(IPapyrusNattableStatus.PASTE_CONFIGURATiON_ERROR, Activator.PLUGIN_ID, PasteSeverityCode.PASTE_ERROR__NO_CONTAINMENT_FEATURE, - String.format(Messages.AbstractPasteImportInsertInNattableManager_PasteConfigurationFeatureHasNotBeenSet, categoryName, current.getDepth()), null); + if(current.getDepth() <= maxDepth){ + + final PasteEObjectConfiguration conf = current.getPasteConfiguration(); + if (conf == null) { + // TODO : add detail of the error in message + status = new PapyrusNattableStatus(IPapyrusNattableStatus.PASTE_CONFIGURATiON_ERROR, Activator.PLUGIN_ID, PasteSeverityCode.PASTE_ERROR__NO_PASTE_CONFIGURATION, + Messages.AbstractPasteImportInsertInNattableManager_ThereIsNoPasteConfgurationForATreeFillingConfiguration, + null); + } else { + + final String elementTypeId = conf.getPastedElementId(); + if (elementTypeId == null || elementTypeId.isEmpty()) { + status = new PapyrusNattableStatus(IPapyrusNattableStatus.PASTE_CONFIGURATiON_ERROR, Activator.PLUGIN_ID, PasteSeverityCode.PASTE_ERROR__NO_ELEMENT_TYPE_IN_PASTE_CONFIGURATION, + Messages.AbstractPasteImportInsertInNattableManager_ThereIsNoElementIdDefinedInThePasteConfiguration, null); + } else if (!ElementTypeUtils.getAllExistingElementTypesIds().contains(elementTypeId)) { + status = new PapyrusNattableStatus(IPapyrusNattableStatus.PASTE_CONFIGURATiON_ERROR, Activator.PLUGIN_ID, PasteSeverityCode.PASTE_ERROR__UNKNOWN_ELEMENT_TYPE, + String.format(Messages.AbstractPasteImportInsertInNattableManager_TheElementTypeIsUnknown, elementTypeId), null); + } + + + if (status.isOK()) { + final EStructuralFeature feature = conf.getPasteElementContainementFeature(); + if (feature == null) { + final IAxis axis = current.getAxisUsedAsAxisProvider(); + final NatTable natTable = manager.getAdapter(NatTable.class); + final LabelProviderContextElementWrapper wrapper = new LabelProviderContextElementWrapper(); + wrapper.setObject(axis); + wrapper.setConfigRegistry(natTable.getConfigRegistry()); + final LabelProviderService serv = natTable.getConfigRegistry().getConfigAttribute(NattableConfigAttributes.LABEL_PROVIDER_SERVICE_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.LABEL_PROVIDER_SERVICE_ID); + ILabelProvider p = serv.getLabelProvider(wrapper); + p = serv.getLabelProvider(Constants.HEADER_LABEL_PROVIDER_CONTEXT); + final String categoryName = p.getText(axis); + status = new PapyrusNattableStatus(IPapyrusNattableStatus.PASTE_CONFIGURATiON_ERROR, Activator.PLUGIN_ID, PasteSeverityCode.PASTE_ERROR__NO_CONTAINMENT_FEATURE, + String.format(Messages.AbstractPasteImportInsertInNattableManager_PasteConfigurationFeatureHasNotBeenSet, categoryName, current.getDepth()), null); + } } } } diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PasteHelperUtils.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PasteHelperUtils.java index 326f3407d54..24618fd070a 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PasteHelperUtils.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PasteHelperUtils.java @@ -14,36 +14,47 @@ package org.eclipse.papyrus.infra.nattable.utils; import java.io.Reader; +import java.util.Map; import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TreeFillingConfiguration; import org.eclipse.papyrus.infra.nattable.parsers.CSVParser; import org.eclipse.papyrus.infra.nattable.parsers.CellIterator; import org.eclipse.papyrus.infra.nattable.parsers.RowIterator; /** - * + * The helper for the paste. */ public class PasteHelperUtils { /** + * The character of the indentation for the single column. + */ + private static final char INDENTATION_CHARACTER = ' '; // $NON-NLS-1$ + + /** * Constructor. */ private PasteHelperUtils() { // to prevent instanciation } - + /** * Manage if this is a paste with overwrite or just a basic paste. * - * @param tableManager The nattable model manager. - * @param pasteHelper The paste helper. - * @param reader The reader of the file. + * @param tableManager + * The nattable model manager. + * @param pasteHelper + * The paste helper. + * @param reader + * The reader of the file. * @return */ public static final boolean isPasteWithOverwrite(final INattableModelManager tableManager, final CSVPasteHelper pasteHelper, final Reader reader) { boolean isPasteWithOverwrite = false; - + final CSVParser parser = pasteHelper.createParser(reader); // Get the pasted text @@ -75,5 +86,89 @@ public class PasteHelperUtils { isPasteWithOverwrite = nbColumnRead != nbExpectedColumn; return isPasteWithOverwrite; } + + /** + * This allows to get the max depth available in the pasted text (to define which paste configuration must be verified). + * + * @param tableManager + * The nattable model manager. + * @param pasteHelper + * The paste helper. + * @param reader + * the reader. + * @return The max depth available in the pasted text. + */ + public static final int getMaxDepthToPaste(final INattableModelManager tableManager, final CSVPasteHelper pasteHelper, final Reader reader) { + int maxDepth = -1; + + if(TableHelper.isTreeTable(tableManager)){ + final Table table = tableManager.getTable(); + final boolean isSingleHeaderColumnTreeTable = TableHelper.isSingleColumnTreeTable(table); + + final CSVParser parser = pasteHelper.createParser(reader, isSingleHeaderColumnTreeTable); + + // Get the pasted text + final RowIterator rowIter = parser.parse(); + + while (rowIter.hasNext()) { + final CellIterator cellIter = rowIter.next(); + + if (!cellIter.hasNext()) { + continue;// to avoid blank line + } + + String valueAsString = cellIter.next(); + int nbReadCell = 1; + + if (isSingleHeaderColumnTreeTable && !valueAsString.isEmpty()) { + // If the table is a single header column, parse the value string to manage the correct depth + // (manage each separator character as empty cell) + while (INDENTATION_CHARACTER == valueAsString.charAt(0)) { + nbReadCell++; + valueAsString = valueAsString.substring(1); + } + } else { + // test if the value is empty (we are in the tree header) + while (cellIter.hasNext() && valueAsString.isEmpty()) { + valueAsString = cellIter.next(); + nbReadCell++; + } + } + final int currentDepth = PasteTreeUtils.getDepth(nbReadCell, FillingConfigurationUtils.getMaxDepthForTree(table), StyleUtils.getHiddenDepths(table), FillingConfigurationUtils.hasTreeFillingConfigurationForDepth(table, 0)); + + if (maxDepth < currentDepth) { + maxDepth = currentDepth; + } + + while (cellIter.hasNext()) { + cellIter.next(); + } + } + } + + return -1 == maxDepth ? Integer.MAX_VALUE : maxDepth; + } + + public static final int getMinDepthOfSelection(final INattableModelManager tableManager, final TableSelectionWrapper tableSelectionWrapper) { + int minDepth = 0; + + if (null != tableSelectionWrapper && !tableSelectionWrapper.getFullySelectedRows().isEmpty() && tableSelectionWrapper.getFullySelectedColumns().isEmpty()) { + minDepth = Integer.MAX_VALUE; + + final Map<Integer, Object> selectedRows = tableSelectionWrapper.getFullySelectedRows(); + + for (int rowIndex : selectedRows.keySet()) { + if (selectedRows.get(rowIndex) instanceof TreeFillingConfiguration) { + if (minDepth > ((TreeFillingConfiguration) selectedRows.get(rowIndex)).getDepth()) { + minDepth = ((TreeFillingConfiguration) selectedRows.get(rowIndex)).getDepth(); + } + } else { + System.out.println(selectedRows.get(rowIndex)); + } + } + } + + return minDepth; + } } |