Author: clopes
Date: 2012-08-13 11:25:17 -0700 (Mon, 13 Aug 2012)
New Revision: 30174
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/vizmap/VisualStyleSerializer.java
core3/impl/trunk/session-impl/impl/src/main/java/org/cytoscape/session/internal/CySessionManagerImpl.java
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/VizMapperMainPanel.java
Log:
Fixes #1345 (Creating a new session doesn't reset the visual styles list)
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/vizmap/VisualStyleSerializer.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/vizmap/VisualStyleSerializer.java
2012-08-13 18:20:41 UTC (rev 30173)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/vizmap/VisualStyleSerializer.java
2012-08-13 18:25:17 UTC (rev 30174)
@@ -281,10 +281,8 @@
vpModelList.add(vpModel);
if (defValue != null) {
- String sValue = null;
+ String sValue =
vp.toSerializableString(defValue);
- sValue =
vp.toSerializableString(defValue);
-
if (sValue != null)
vpModel.setDefault(sValue);
}
Modified:
core3/impl/trunk/session-impl/impl/src/main/java/org/cytoscape/session/internal/CySessionManagerImpl.java
===================================================================
---
core3/impl/trunk/session-impl/impl/src/main/java/org/cytoscape/session/internal/CySessionManagerImpl.java
2012-08-13 18:20:41 UTC (rev 30173)
+++
core3/impl/trunk/session-impl/impl/src/main/java/org/cytoscape/session/internal/CySessionManagerImpl.java
2012-08-13 18:25:17 UTC (rev 30174)
@@ -234,12 +234,10 @@
@Override
public void setCurrentSession(CySession sess, final String fileName) {
- boolean emptySession = sess == null;
-
// Always remove the current session first
- disposeCurrentSession(!emptySession);
+ disposeCurrentSession();
- if (emptySession) {
+ if (sess == null) {
logger.debug("Creating empty session...");
final Set<VisualStyle> styles =
vmMgr.getAllVisualStyles();
final Set<CyProperty<?>> props = getAllProperties();
@@ -274,17 +272,15 @@
cyEventHelper.fireEvent(new SessionLoadedEvent(this,
currentSession, getCurrentSessionFileName()));
}
-
/**
* Update current session session object when session is saved.
*/
@Override
public void handleEvent(SessionSavedEvent e) {
-
- if(currentSession != e.getSavedSession())
+ if (currentSession != e.getSavedSession())
currentSession = e.getSavedSession();
- if(currentFileName != e.getSavedFileName())
+ if (currentFileName != e.getSavedFileName())
currentFileName = e.getSavedFileName();
}
@@ -317,7 +313,7 @@
}
private Set<CyProperty<?>> getAllProperties() {
- Set<CyProperty<?>> set = new
HashSet<CyProperty<?>>(sessionProperties);
+ final Set<CyProperty<?>> set = new
HashSet<CyProperty<?>>(sessionProperties);
if (bookmarks != null)
set.add(bookmarks);
@@ -325,7 +321,7 @@
return set;
}
- private void restoreProperties(CySession sess) {
+ private void restoreProperties(final CySession sess) {
for (CyProperty<?> cyProps : sess.getProperties()) {
final Properties serviceProps = new Properties();
serviceProps.setProperty("cyPropertyName",
cyProps.getName());
@@ -333,7 +329,7 @@
}
}
- private void restoreNetworks(CySession sess) {
+ private void restoreNetworks(final CySession sess) {
logger.debug("Restoring networks...");
Set<CyNetwork> networks = sess.getNetworks();
@@ -342,11 +338,11 @@
}
}
- private void restoreNetworkViews(CySession sess) {
+ private void restoreNetworkViews(final CySession sess) {
logger.debug("Restoring network views...");
Set<CyNetworkView> netViews = sess.getNetworkViews();
-
List<CyNetworkView> selectedViews = new
ArrayList<CyNetworkView>();
+
for (CyNetworkView nv : netViews) {
CyNetwork network = nv.getModel();
if (network.getRow(network).get(CyNetwork.SELECTED,
Boolean.class)) {
@@ -428,13 +424,13 @@
}
}
- private void disposeCurrentSession(boolean removeVisualStyles) {
+ private void disposeCurrentSession() {
logger.debug("Disposing current session...");
// Destroy network views
- Set<CyNetworkView> netViews = nvMgr.getNetworkViewSet();
+ final Set<CyNetworkView> netViews = nvMgr.getNetworkViewSet();
- for (CyNetworkView nv : netViews) {
+ for (final CyNetworkView nv : netViews) {
nvMgr.destroyNetworkView(nv);
}
@@ -443,25 +439,20 @@
// Destroy networks
final Set<CyNetwork> networks = netMgr.getNetworkSet();
- for (CyNetwork n : networks) {
+ for (final CyNetwork n : networks) {
netMgr.destroyNetwork(n);
}
netMgr.reset();
// Destroy styles
- if (removeVisualStyles) {
- logger.debug("Removing current visual styles...");
- VisualStyle defaultStyle =
vmMgr.getDefaultVisualStyle();
- List<VisualStyle> allStyles = new
ArrayList<VisualStyle>(vmMgr.getAllVisualStyles());
+ logger.debug("Removing current visual styles...");
+ final VisualStyle defaultStyle = vmMgr.getDefaultVisualStyle();
+ final List<VisualStyle> allStyles = new
ArrayList<VisualStyle>(vmMgr.getAllVisualStyles());
- for (int i = 0; i < allStyles.size(); i++) {
- VisualStyle vs = allStyles.get(i);
-
- if (!vs.equals(defaultStyle)) {
- vmMgr.removeVisualStyle(vs);
- }
- }
+ for (final VisualStyle vs : allStyles) {
+ if (!vs.equals(defaultStyle))
+ vmMgr.removeVisualStyle(vs);
}
// Destroy tables
Modified:
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/VizMapperMainPanel.java
===================================================================
---
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/VizMapperMainPanel.java
2012-08-13 18:20:41 UTC (rev 30173)
+++
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/VizMapperMainPanel.java
2012-08-13 18:25:17 UTC (rev 30174)
@@ -54,6 +54,8 @@
import org.cytoscape.application.swing.CytoPanelComponent;
import org.cytoscape.application.swing.CytoPanelName;
import org.cytoscape.model.CyNetwork;
+import org.cytoscape.session.events.SessionLoadedEvent;
+import org.cytoscape.session.events.SessionLoadedListener;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.presentation.RenderingEngine;
import org.cytoscape.view.presentation.property.BasicVisualLexicon;
@@ -98,7 +100,7 @@
*/
public class VizMapperMainPanel extends AbstractVizMapperPanel implements
VisualStyleAddedListener,
VisualStyleSetListener, VisualStyleAboutToBeRemovedListener,
PopupMenuListener, CytoPanelComponent,
- PropertyChangeListener, LexiconStateChangedListener,
SetCurrentVisualStyleListener {
+ PropertyChangeListener, LexiconStateChangedListener,
SetCurrentVisualStyleListener, SessionLoadedListener {
private final static long serialVersionUID = 1202339867854959L;
@@ -108,6 +110,8 @@
private static final String TAB_TITLE = "VizMapper";
private final DefaultViewMouseListener defaultViewMouseListener;
+ private final ImportDefaultVizmapTaskFactory importDefVizmapTaskFactory;
+ private final TaskManager<?, ?> taskManager;
/**
* Create new instance of VizMapperMainPanel object. GUI layout is
handled
@@ -131,20 +135,22 @@
final
VizMapPropertySheetBuilder vizMapPropertySheetBuilder,
final
EditorWindowManager editorWindowManager,
final
CyApplicationManager applicationManager,
- final
ImportDefaultVizmapTaskFactory taskFactory,
- final TaskManager<?,
?> tManager,
+ final
ImportDefaultVizmapTaskFactory importDefVizmapTaskFactory,
+ final TaskManager<?,
?> taskManager,
final
SetViewModeAction viewModeAction) {
super(vsFactory, defViewEditor, iconMgr, colorMgr, vmm,
menuMgr, editorFactory, propertySheetPanel,
vizMapPropertySheetBuilder,
editorWindowManager, applicationManager, viewModeAction);
this.defaultViewMouseListener = new
DefaultViewMouseListener(defViewEditor, this, vmm);
+ this.importDefVizmapTaskFactory = importDefVizmapTaskFactory;
+ this.taskManager = taskManager;
// Initialize all components
initPanel();
viewModeAction.addPropertyChangeListener(this);
// Load default styles
- tManager.execute(taskFactory.createTaskIterator());
+ loadDefaultStyles();
}
private void initPanel() {
@@ -165,6 +171,10 @@
});
}
+ private void loadDefaultStyles() {
+
taskManager.execute(importDefVizmapTaskFactory.createTaskIterator());
+ }
+
private void resizeImage() {
final VisualStyle style = vmm.getCurrentVisualStyle();
@@ -391,12 +401,11 @@
}
@Override
- public void handleEvent(VisualStyleSetEvent e) {
+ public void handleEvent(final VisualStyleSetEvent e) {
final CyNetworkView view = e.getNetworkView();
if (view.equals(applicationManager.getCurrentNetworkView())) {
- // Only switch the selected style if the network view
is the current
- // one
+ // Only switch the selected style if the network view
is the current one
final VisualStyle style = e.getVisualStyle();
final VisualStyle lastStyle = (VisualStyle)
visualStyleComboBox.getSelectedItem();
@@ -407,6 +416,14 @@
}
@Override
+ public void handleEvent(final SessionLoadedEvent e) {
+ if (e.getLoadedFileName() == null) {
+ // New empty session: Load the default styles again.
+ loadDefaultStyles();
+ }
+ }
+
+ @Override
public String getTitle() {
return TAB_TITLE;
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.