Skip to content

Commit 6a596ac

Browse files
author
mpschr
committed
Remove Layers!
1 parent 21276a8 commit 6a596ac

File tree

5 files changed

+135
-1
lines changed

5 files changed

+135
-1
lines changed

org.gitools.heatmap/src/main/java/org/gitools/heatmap/Heatmap.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.gitools.heatmap.header.HeatmapTextLabelsHeader;
2929
import org.gitools.heatmap.plugins.Plugins;
3030
import org.gitools.matrix.model.MatrixPosition;
31+
import org.gitools.matrix.model.hashmatrix.HashMatrix;
3132
import org.gitools.resource.Resource;
3233

3334
import javax.xml.bind.annotation.*;
@@ -282,6 +283,17 @@ public Plugins getPluggedBoxes() {
282283
return pluggedBoxes;
283284
}
284285

286+
public void removeLayer(HeatmapLayer layer) {
287+
// Remove Heatmap Layer
288+
getLayers().remove(layer);
289+
// Remove HashMatrix Layer
290+
IMatrix data = getContents();
291+
if (data instanceof HashMatrix) {
292+
IMatrixLayer dataLayer = data.getLayers().get(layer.getId());
293+
((HashMatrix) data).removeLayer(dataLayer);
294+
}
295+
}
296+
285297

286298
transient Map<IKey, Object> metadata;
287299

org.gitools.heatmap/src/main/java/org/gitools/heatmap/HeatmapLayers.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,21 @@ public void setTopLayerIndex(int layerIndex) {
168168
EventUtils.moveListeners(oldLayer, newLayer);
169169
}
170170

171+
public void remove(HeatmapLayer layer) {
172+
if(getTopLayer() == layer) {
173+
int idx = layers.indexOf(layer) - 1;
174+
if (idx < 0) {
175+
setTopLayer(get(idx));
176+
} else {
177+
setTopLayer(get(0));
178+
}
179+
} else if(layers.indexOf(getTopLayer()) == layers.size()-1 ) {
180+
setTopLayer(layers.get(layers.size()-2));
181+
}
182+
this.layers.remove(layer);
183+
this.updateLayers();
184+
}
185+
171186
@Override
172187
public String[] getIds() {
173188
return layersIdToIndex.keySet().toArray(new String[size()]);

org.gitools.matrix/src/main/java/org/gitools/matrix/model/hashmatrix/HashMatrix.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public void addLayer(IMatrixLayer layer) {
135135
public void removeLayer(IMatrixLayer layer) {
136136
getLayers().remove(layer);
137137
values.remove(layer.getId());
138+
hasChanged = true;
138139
}
139140

140141
public void copyLayerValues(String layerId, HashMatrix fromMatrix) {
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* #%L
3+
* gitools-ui-app
4+
* %%
5+
* Copyright (C) 2013 Universitat Pompeu Fabra - Biomedical Genomics group
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as
9+
* published by the Free Software Foundation, either version 3 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/gpl-3.0.html>.
20+
* #L%
21+
*/
22+
package org.gitools.ui.app.actions.edit;
23+
24+
import org.gitools.api.analysis.IProgressMonitor;
25+
import org.gitools.heatmap.Heatmap;
26+
import org.gitools.heatmap.HeatmapLayer;
27+
import org.gitools.matrix.model.hashmatrix.HashMatrix;
28+
import org.gitools.ui.core.Application;
29+
import org.gitools.ui.core.HeatmapPosition;
30+
import org.gitools.ui.core.actions.HeatmapAction;
31+
import org.gitools.ui.core.actions.dynamicactions.IHeatmapLayerAction;
32+
import org.gitools.ui.core.commands.AbstractCommand;
33+
import org.gitools.ui.platform.icons.IconNames;
34+
import org.gitools.ui.platform.progress.JobThread;
35+
36+
import javax.swing.*;
37+
import java.awt.event.ActionEvent;
38+
39+
public class RemoveLayerAction extends HeatmapAction implements IHeatmapLayerAction {
40+
41+
42+
private HeatmapLayer layer;
43+
44+
public RemoveLayerAction() {
45+
super("Delete data layer...");
46+
setSmallIconFromResource(IconNames.remove16);
47+
}
48+
49+
@Override
50+
public boolean isEnabledByModel(Object model) {
51+
return (model instanceof Heatmap) && (((Heatmap) model).getContents() instanceof HashMatrix);
52+
}
53+
54+
@Override
55+
public void actionPerformed(ActionEvent e) {
56+
57+
58+
Object[] options = {"Cancel",
59+
"No!",
60+
"Ok"};
61+
int n = JOptionPane.showOptionDialog(Application.get(),
62+
"<html>Would you like to <b>delete</b> the selected data layer?",
63+
"Delete values from heatmap",
64+
JOptionPane.YES_NO_CANCEL_OPTION,
65+
JOptionPane.QUESTION_MESSAGE,
66+
null,
67+
options,
68+
options[2]);
69+
70+
if (n == 1 | n == 0) {
71+
return;
72+
}
73+
74+
AbstractCommand cmd = new AbstractCommand() {
75+
76+
@Override
77+
public void execute(IProgressMonitor monitor) throws CommandException {
78+
79+
getHeatmap().removeLayer(layer);
80+
81+
}
82+
};
83+
84+
85+
JobThread.execute(Application.get(), cmd);
86+
Application.get().showNotification("Data layer deleted");
87+
}
88+
89+
90+
91+
@Override
92+
public void onConfigure(HeatmapLayer object, HeatmapPosition position) {
93+
setLayer(object);
94+
}
95+
96+
public void setLayer(HeatmapLayer layer) {
97+
this.layer = layer;
98+
}
99+
100+
public HeatmapLayer getLayer() {
101+
return layer;
102+
}
103+
}

org.gitools.ui.app/src/main/java/org/gitools/ui/app/heatmap/popupmenus/PopupMenuActions.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ private static ActionSet getHeatmapMenu(MatrixDimensionKey dimensionKey) {
122122
new EditLayerAction("Edit..."),
123123
BaseAction.separator,
124124
new MoveUpLayerAction(),
125-
new MoveDownLayerAction()
125+
new MoveDownLayerAction(),
126+
BaseAction.separator,
127+
new RemoveLayerAction(),
128+
126129
});
127130

128131

0 commit comments

Comments
 (0)