Skip to content
Snippets Groups Projects
Commit 992e8161 authored by GIRARDOT Raphael's avatar GIRARDOT Raphael Committed by MADELA Patrick
Browse files

some code cleaning

parent 7bb93e09
No related branches found
No related tags found
No related merge requests found
...@@ -69,6 +69,10 @@ ...@@ -69,6 +69,10 @@
<groupId>org.swinglabs</groupId> <groupId>org.swinglabs</groupId>
<artifactId>swingx</artifactId> <artifactId>swingx</artifactId>
</dependency> </dependency>
<dependency>
<groupId>fr.soleil.lib</groupId>
<artifactId>BasicUtilities</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -14,6 +14,7 @@ import fr.soleil.docking.exception.DockingException; ...@@ -14,6 +14,7 @@ import fr.soleil.docking.exception.DockingException;
import fr.soleil.docking.perspective.IPerspective; import fr.soleil.docking.perspective.IPerspective;
import fr.soleil.docking.perspective.IPerspectiveFactory; import fr.soleil.docking.perspective.IPerspectiveFactory;
import fr.soleil.docking.view.IViewFactory; import fr.soleil.docking.view.IViewFactory;
import fr.soleil.lib.project.ObjectUtils;
/** /**
* A class that prepares docking. Obtain your RootWindow from this class. * A class that prepares docking. Obtain your RootWindow from this class.
...@@ -133,25 +134,26 @@ public abstract class ADockingManager implements PropertyChangeListener { ...@@ -133,25 +134,26 @@ public abstract class ADockingManager implements PropertyChangeListener {
@Override @Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
if (evt.getSource().equals(perspectiveFactory)) { if (evt != null) {
if (evt.getPropertyName().equals(IPerspectiveFactory.SELECTED_PERSPECTIVE)) { if (ObjectUtils.sameObject(perspectiveFactory, evt.getSource())) {
IPerspective oldd = (IPerspective) evt.getOldValue(); if (IPerspectiveFactory.SELECTED_PERSPECTIVE.equals(evt.getPropertyName())) {
IPerspective neww = (IPerspective) evt.getNewValue(); IPerspective oldd = (IPerspective) evt.getOldValue();
try { IPerspective neww = (IPerspective) evt.getNewValue();
if (automaticallySavePerspective) { try {
this.savePerspective(oldd); if (automaticallySavePerspective) {
this.savePerspective(oldd);
}
this.loadPerspective(neww);
} catch (DockingException e) {
e.printStackTrace();
} }
this.loadPerspective(neww);
} catch (DockingException e) {
e.printStackTrace();
} }
} } else if (ObjectUtils.sameObject(viewFactory, evt.getSource())) {
} else if (evt.getSource().equals(viewFactory)) { if (IViewFactory.VIEWS.equals(evt.getPropertyName())) {
if (evt.getPropertyName().equals(IViewFactory.VIEWS)) { this.updateViews(evt);
this.updateViews(evt); }
} }
} }
} }
protected abstract void updateViews(PropertyChangeEvent evt); protected abstract void updateViews(PropertyChangeEvent evt);
......
...@@ -55,7 +55,7 @@ public class NewPerspectiveAction extends AbstractAction { ...@@ -55,7 +55,7 @@ public class NewPerspectiveAction extends AbstractAction {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
IPerspective current = factory.getSelectedPerspective(); IPerspective current = factory.getSelectedPerspective();
String result = JOptionPane.showInputDialog("Enter the name of the new perspective"); String result = JOptionPane.showInputDialog("Enter the name of the new perspective");
if (!result.equals("")) { if ((result != null) && (!result.trim().isEmpty())) {
IPerspective p = factory.createPerspective(result); IPerspective p = factory.createPerspective(result);
byte[] array = current.getByteArray(); byte[] array = current.getByteArray();
byte[] copy = (array == null ? null : array.clone()); byte[] copy = (array == null ? null : array.clone());
......
...@@ -13,6 +13,7 @@ import javax.swing.KeyStroke; ...@@ -13,6 +13,7 @@ import javax.swing.KeyStroke;
import fr.soleil.docking.perspective.IPerspective; import fr.soleil.docking.perspective.IPerspective;
import fr.soleil.docking.perspective.IPerspectiveFactory; import fr.soleil.docking.perspective.IPerspectiveFactory;
import fr.soleil.lib.project.ObjectUtils;
public class SelectPerspectiveAction extends AbstractAction implements PropertyChangeListener { public class SelectPerspectiveAction extends AbstractAction implements PropertyChangeListener {
...@@ -65,11 +66,13 @@ public class SelectPerspectiveAction extends AbstractAction implements PropertyC ...@@ -65,11 +66,13 @@ public class SelectPerspectiveAction extends AbstractAction implements PropertyC
@Override @Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(IPerspectiveFactory.SELECTED_PERSPECTIVE)) { if (evt != null) {
if (evt.getNewValue().equals(this.perspective)) { if (IPerspectiveFactory.SELECTED_PERSPECTIVE.equals(evt.getPropertyName())) {
putValue(SELECTED_KEY, true); if (ObjectUtils.sameObject(evt.getNewValue(), this.perspective)) {
} else { putValue(SELECTED_KEY, true);
putValue(SELECTED_KEY, false); } else {
putValue(SELECTED_KEY, false);
}
} }
} }
} }
......
...@@ -27,9 +27,11 @@ public class PerspectiveMenu extends javax.swing.JMenu implements PropertyChange ...@@ -27,9 +27,11 @@ public class PerspectiveMenu extends javax.swing.JMenu implements PropertyChange
@Override @Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
if (evt.getSource() instanceof IPerspectiveFactory) { if (evt != null) {
if (evt.getPropertyName().equals(IPerspectiveFactory.PERSPECTIVES)) { if (evt.getSource() instanceof IPerspectiveFactory) {
if (IPerspectiveFactory.PERSPECTIVES.equals(evt.getPropertyName())) {
// TODO
}
} }
} }
} }
......
...@@ -15,6 +15,7 @@ import fr.soleil.docking.action.NewPerspectiveAction; ...@@ -15,6 +15,7 @@ import fr.soleil.docking.action.NewPerspectiveAction;
import fr.soleil.docking.action.RemovePerspectiveAction; import fr.soleil.docking.action.RemovePerspectiveAction;
import fr.soleil.docking.action.SelectPerspectiveAction; import fr.soleil.docking.action.SelectPerspectiveAction;
import fr.soleil.docking.exception.DockingException; import fr.soleil.docking.exception.DockingException;
import fr.soleil.lib.project.ObjectUtils;
public class PerspectiveFactory implements IPerspectiveFactory { public class PerspectiveFactory implements IPerspectiveFactory {
...@@ -63,12 +64,15 @@ public class PerspectiveFactory implements IPerspectiveFactory { ...@@ -63,12 +64,15 @@ public class PerspectiveFactory implements IPerspectiveFactory {
} }
@Override @Override
public IPerspective getPerspective(Object name) { public IPerspective getPerspective(Object id) {
IPerspective result = null; IPerspective result = null;
for (IPerspective perspective : perspectives) { if (id instanceof String) {
if (perspective.getName().equalsIgnoreCase((String) name)) { String name = (String) id;
result = perspective; for (IPerspective perspective : perspectives) {
break; if (name.equalsIgnoreCase(perspective.getName())) {
result = perspective;
break;
}
} }
} }
return result; return result;
...@@ -81,7 +85,8 @@ public class PerspectiveFactory implements IPerspectiveFactory { ...@@ -81,7 +85,8 @@ public class PerspectiveFactory implements IPerspectiveFactory {
@Override @Override
public void setSelectedPerspective(IPerspective selectedPerspective) { public void setSelectedPerspective(IPerspective selectedPerspective) {
if (!this.selectedPerspective.equals(selectedPerspective) && this.perspectives.contains(selectedPerspective)) { if ((selectedPerspective != null) && (!selectedPerspective.equals(this.selectedPerspective))
&& perspectives.contains(selectedPerspective)) {
IPerspective old = this.selectedPerspective; IPerspective old = this.selectedPerspective;
this.selectedPerspective = selectedPerspective; this.selectedPerspective = selectedPerspective;
support.firePropertyChange(SELECTED_PERSPECTIVE, old, this.selectedPerspective); support.firePropertyChange(SELECTED_PERSPECTIVE, old, this.selectedPerspective);
...@@ -219,8 +224,14 @@ public class PerspectiveFactory implements IPerspectiveFactory { ...@@ -219,8 +224,14 @@ public class PerspectiveFactory implements IPerspectiveFactory {
@Override @Override
public IPerspective removePerspective(final IPerspective p) { public IPerspective removePerspective(final IPerspective p) {
int index = perspectives.indexOf(p); int index;
if (index != -1 && !(p instanceof ResourcePerspective) && !p.getName().equals(defaultPerspectiveName)) { if (p == null) {
index = -1;
} else {
index = perspectives.indexOf(p);
}
if ((index > -1) && (!(p instanceof ResourcePerspective))
&& (!ObjectUtils.sameObject(p.getName(), defaultPerspectiveName))) {
// Exist and it's not the default perspective // Exist and it's not the default perspective
perspectives.remove(index); perspectives.remove(index);
support.fireIndexedPropertyChange(PERSPECTIVES, index, p, null); support.fireIndexedPropertyChange(PERSPECTIVES, index, p, null);
......
...@@ -16,6 +16,7 @@ import java.util.prefs.Preferences; ...@@ -16,6 +16,7 @@ import java.util.prefs.Preferences;
import javax.swing.Action; import javax.swing.Action;
import fr.soleil.docking.action.ViewAction; import fr.soleil.docking.action.ViewAction;
import fr.soleil.lib.project.ObjectUtils;
public class ViewFactory implements IViewFactory { public class ViewFactory implements IViewFactory {
...@@ -32,7 +33,7 @@ public class ViewFactory implements IViewFactory { ...@@ -32,7 +33,7 @@ public class ViewFactory implements IViewFactory {
public IView getView(Object id) { public IView getView(Object id) {
IView result = null; IView result = null;
for (IView view : views) { for (IView view : views) {
if (view.getId().equals(id)) { if (ObjectUtils.sameObject(id, view.getId())) {
result = view; result = view;
break; break;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment