Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Issue warning before unlinking all tags or attachements (close #6748)

  • Loading branch information...
commit 8965057445f59d2ce5e0e5dd6e9326cc8f2af574 1 parent 9eec077
@jburel jburel authored
View
54 components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/AnnotationDataUI.java
@@ -370,13 +370,15 @@ public void mouseReleased(MouseEvent e) {
UIUtilities.unifiedButtonLookAndFeel(removeTagsButton);
removeTagsButton.setBackground(UIUtilities.BACKGROUND_COLOR);
removeTagsButton.setToolTipText("Unlink Tags.");
- removeTagsButton.addActionListener(controller);
+ removeTagsButton.addMouseListener(controller);
+ //removeTagsButton.addActionListener(controller);
removeTagsButton.setActionCommand(""+EditorControl.REMOVE_TAGS);
removeDocsButton = new JButton(icons.getIcon(IconManager.MINUS_12));
UIUtilities.unifiedButtonLookAndFeel(removeDocsButton);
removeDocsButton.setBackground(UIUtilities.BACKGROUND_COLOR);
removeDocsButton.setToolTipText("Unlink Attachments.");
- removeDocsButton.addActionListener(controller);
+ //removeDocsButton.addActionListener(controller);
+ removeDocsButton.addMouseListener(controller);
removeDocsButton.setActionCommand(""+EditorControl.REMOVE_DOCS);
selectedValue = 0;
@@ -1240,6 +1242,54 @@ void handleObjectsSelection(Class type, Collection objects, boolean fire)
}
/**
+ * Returns <code>true</code> some tags can be unlink,
+ * <code>false</code> otherwise.
+ *
+ * @return See above.
+ */
+ boolean hasTagsToUnlink()
+ {
+ if (tagsDocList.size() == 0) return false;
+ DocComponent doc;
+ Object object;
+ Iterator<DocComponent> i = tagsDocList.iterator();
+ while (i.hasNext()) {
+ doc = i.next();
+ object = doc.getData();
+ if (doc.canUnlink()) {
+ if (object instanceof TagAnnotationData) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns <code>true</code> some tags can be unlink,
+ * <code>false</code> otherwise.
+ *
+ * @return See above.
+ */
+ boolean hasAttachmentsToUnlink()
+ {
+ if (filesDocList.size() == 0) return false;
+ DocComponent doc;
+ Object object;
+ Iterator<DocComponent> i = filesDocList.iterator();
+ while (i.hasNext()) {
+ doc = i.next();
+ object = doc.getData();
+ if (doc.canUnlink()) {
+ if (object instanceof FileAnnotationData) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
* Overridden to set the title of the component.
* @see AnnotationUI#getComponentTitle()
*/
View
60 components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorControl.java
@@ -29,6 +29,10 @@
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
@@ -39,8 +43,11 @@
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
+
+import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
+import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.filechooser.FileFilter;
@@ -81,6 +88,7 @@
import org.openmicroscopy.shoola.util.filter.file.TIFFFilter;
import org.openmicroscopy.shoola.util.filter.file.WordFilter;
import org.openmicroscopy.shoola.util.filter.file.XMLFilter;
+import org.openmicroscopy.shoola.util.ui.MessageBox;
import org.openmicroscopy.shoola.util.ui.UIUtilities;
import org.openmicroscopy.shoola.util.ui.filechooser.FileChooser;
import org.openmicroscopy.shoola.util.ui.omeeditpane.OMEWikiComponent;
@@ -106,7 +114,7 @@
* @since OME3.0
*/
class EditorControl
- implements ActionListener, ChangeListener, PropertyChangeListener
+ implements ActionListener, ChangeListener, PropertyChangeListener, MouseListener
{
/** Bound property indicating that the save status has been modified. */
@@ -708,16 +716,64 @@ public void actionPerformed(ActionEvent e)
case RELOAD_SCRIPT:
view.reloadScript();
break;
+ /*
case REMOVE_TAGS:
view.removeTags();
break;
case REMOVE_DOCS:
view.removeAttachedFiles();
break;
+ */
case SAVE_AS:
saveAsJPEG();
}
}
+
+ /**
+ * Removes the tags or files.
+ * @see MouseListener#mouseReleased(MouseEvent)
+ */
+ public void mouseReleased(MouseEvent e)
+ {
+ JButton src = (JButton) e.getSource();
+ int index = Integer.parseInt(src.getActionCommand());
+ Point p = e.getPoint();
+ SwingUtilities.convertPointToScreen(p, src);
+ switch (index) {
+ case REMOVE_TAGS:
+ view.removeTags(p);
+ break;
+ case REMOVE_DOCS:
+ view.removeAttachedFiles(p);
+ }
+ }
-}
+ /**
+ * Required by the {@link MouseListener} I/F but no-operation
+ * implementation in our case.
+ * @see MouseListener#mouseClicked(MouseEvent)
+ */
+ public void mouseClicked(MouseEvent e) {}
+
+ /**
+ * Required by the {@link MouseListener} I/F but no-operation
+ * implementation in our case.
+ * @see MouseListener#mouseEntered(MouseEvent)
+ */
+ public void mouseEntered(MouseEvent e) {}
+
+ /**
+ * Required by the {@link MouseListener} I/F but no-operation
+ * implementation in our case.
+ * @see MouseListener#mouseExited(MouseEvent)
+ */
+ public void mouseExited(MouseEvent e) {}
+
+ /**
+ * Required by the {@link MouseListener} I/F but no-operation
+ * implementation in our case.
+ * @see MouseListener#mousePressed(MouseEvent)
+ */
+ public void mousePressed(MouseEvent e) {}
+}
View
10 components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorModel.java
@@ -39,6 +39,8 @@
import java.util.Set;
import java.util.Map.Entry;
+import javax.swing.JFrame;
+
//Third-party libraries
//Application-internal dependencies
@@ -2818,5 +2820,11 @@ boolean isLargeImage()
return false;
}
+ /**
+ * Returns the parent UI.
+ *
+ * @return See above.
+ */
+ JFrame getRefFrame() { return parent.getParentUI(); }
+
}
-
View
39 components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorUI.java
@@ -29,6 +29,7 @@
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
+import java.awt.Dimension;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
@@ -54,6 +55,7 @@
import org.openmicroscopy.shoola.env.data.model.ScriptObject;
import org.openmicroscopy.shoola.env.event.EventBus;
import org.openmicroscopy.shoola.env.rnd.RenderingControl;
+import org.openmicroscopy.shoola.util.ui.MessageBox;
import org.openmicroscopy.shoola.util.ui.UIUtilities;
import pojos.AnnotationData;
import pojos.DataObject;
@@ -555,11 +557,24 @@ void removeObject(DataObject data)
}
}
- /** Removes the tags. */
- void removeTags()
+ /**
+ * Removes the tags.
+ *
+ * @param location The location of the mouse pressed.
+ */
+ void removeTags(Point location)
{
- List<TagAnnotationData> list = generalPane.removeTags();
- if (list.size() > 0) saveData(true);
+
+ if (!generalPane.hasTagsToUnlink()) return;
+ MessageBox box = new MessageBox(model.getRefFrame(),
+ "Remove All Tags",
+ "Are you sure you want to remove all Tags?");
+ Dimension d = box.getPreferredSize();
+ Point p = new Point(location.x-d.width/2, location.y);
+ if (box.showMsgBox(p) == MessageBox.YES_OPTION) {
+ List<TagAnnotationData> list = generalPane.removeTags();
+ if (list.size() > 0) saveData(true);
+ }
}
/**
@@ -594,12 +609,20 @@ void removeAttachedFile(Object file)
/**
* Returns the collection of attachments.
*
- * @return See above.
+ * @param location The location of the mouse pressed.
*/
- void removeAttachedFiles()
+ void removeAttachedFiles(Point location)
{
- List<FileAnnotationData> list = generalPane.removeAttachedFiles();
- if (list.size() > 0) saveData(true);
+ if (!generalPane.hasAttachmentsToUnlink()) return;
+ MessageBox box = new MessageBox(model.getRefFrame(),
+ "Remove All Attachments",
+ "Are you sure you want to remove all Attachments?");
+ Dimension d = box.getPreferredSize();
+ Point p = new Point(location.x-d.width/2, location.y);
+ if (box.showMsgBox(p) == MessageBox.YES_OPTION) {
+ List<FileAnnotationData> list = generalPane.removeAttachedFiles();
+ if (list.size() > 0) saveData(true);
+ }
}
/**
View
22 components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/GeneralPaneUI.java
@@ -527,6 +527,28 @@ void removeAttachedFile(Object file)
}
/**
+ * Returns <code>true</code> some tags can be unlink,
+ * <code>false</code> otherwise.
+ *
+ * @return See above.
+ */
+ boolean hasAttachmentsToUnlink()
+ {
+ return annotationUI.hasAttachmentsToUnlink();
+ }
+
+ /**
+ * Returns <code>true</code> some tags can be unlink,
+ * <code>false</code> otherwise.
+ *
+ * @return See above.
+ */
+ boolean hasTagsToUnlink()
+ {
+ return annotationUI.hasTagsToUnlink();
+ }
+
+ /**
* Removes the annotation from the view.
*
* @param annotation The annotation to remove.
View
8 components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewer.java
@@ -34,6 +34,7 @@
import java.util.List;
import java.util.Map;
import javax.swing.JComponent;
+import javax.swing.JFrame;
//Third-party libraries
@@ -619,4 +620,11 @@ public void setThumbnails(Map<Long, BufferedImage> thumbnails,
*/
void onGroupSwitched(boolean success);
+ /**
+ * Returns the parent UI.
+ *
+ * @return See above.
+ */
+ JFrame getParentUI();
+
}
View
12 components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewerComponent.java
@@ -340,6 +340,18 @@ public JComponent getUI()
/**
* Implemented as specified by the {@link MetadataViewer} interface.
+ * @see MetadataViewer#getParentUI()
+ */
+ public JFrame getParentUI()
+ {
+ if (model.getState() == DISCARDED)
+ throw new IllegalStateException("This method cannot be invoked " +
+ "in the DISCARDED state.");
+ return view;
+ }
+
+ /**
+ * Implemented as specified by the {@link MetadataViewer} interface.
* @see MetadataViewer#setRootObject(Object, long)
*/
public void setRootObject(Object root, long userID)
Please sign in to comment.
Something went wrong with that request. Please try again.