]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network.ui/src/org/simantics/district/network/ui/table/PasteDataCommandHandler.java
Fixed District diagram viewer to allow moving of vertices again.
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / table / PasteDataCommandHandler.java
1 package org.simantics.district.network.ui.table;
2
3 import java.util.Collection;
4
5 import org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler;
6 import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
7 import org.eclipse.nebula.widgets.nattable.layer.event.ColumnVisualUpdateEvent;
8 import org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent;
9 import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
10 import org.eclipse.swt.dnd.Clipboard;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13
14 public class PasteDataCommandHandler extends AbstractLayerCommandHandler<CustomPasteDataCommand> {
15
16         private static final Logger LOGGER = LoggerFactory.getLogger(PasteDataCommandHandler.class);
17
18         private final SelectionLayer selectionLayer;
19         private final DataLayer dataLayer;
20         private final Clipboard cpb;
21         private final TableDataProvider provider;
22
23         public PasteDataCommandHandler(TableDataProvider provider, DataLayer dataLayer, SelectionLayer selectionLayer, Clipboard cpb) {
24                 this.provider = provider;
25                 this.dataLayer = dataLayer;
26                 this.selectionLayer = selectionLayer;
27                 this.cpb = cpb;
28         }
29
30     @Override
31     public Class<CustomPasteDataCommand> getCommandClass() {
32         return CustomPasteDataCommand.class;
33     }
34
35     @Override
36     protected boolean doCommand(CustomPasteDataCommand command) {
37         String[][] fullData = command.data;
38         int pasteRow = command.pasteRow;
39         Collection<Integer> pasteColumn = command.getColumnPositions();
40         if (pasteRow > -1) {
41             provider.setDataValues(pasteColumn, pasteRow, fullData);
42             dataLayer.fireLayerEvent(new StructuralRefreshEvent(dataLayer));
43         }
44         return true;
45     }
46 }
47