Skip to content

Commit

Permalink
Issue warning before unlinking all tags or attachements (close #6748)
Browse files Browse the repository at this point in the history
  • Loading branch information
jburel committed Sep 13, 2011
1 parent 9eec077 commit 8965057
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 13 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -1239,6 +1241,54 @@ List<TagAnnotationData> removeTags()
return list;
}

/**
* 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()
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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. */
Expand Down Expand Up @@ -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) {}

}
Expand Up @@ -39,6 +39,8 @@
import java.util.Set;
import java.util.Map.Entry;

import javax.swing.JFrame;

//Third-party libraries

//Application-internal dependencies
Expand Down Expand Up @@ -2818,5 +2820,11 @@ boolean isLargeImage()
return false;
}

/**
* Returns the parent UI.
*
* @return See above.
*/
JFrame getRefFrame() { return parent.getParentUI(); }

}

Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down
Expand Up @@ -526,6 +526,28 @@ List<TagAnnotationData> removeTags()
return annotationUI.removeTags();
}

/**
* 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.
*
Expand Down
Expand Up @@ -34,6 +34,7 @@
import java.util.List;
import java.util.Map;
import javax.swing.JComponent;
import javax.swing.JFrame;

//Third-party libraries

Expand Down Expand Up @@ -619,4 +620,11 @@ public void setThumbnails(Map<Long, BufferedImage> thumbnails,
*/
void onGroupSwitched(boolean success);

/**
* Returns the parent UI.
*
* @return See above.
*/
JFrame getParentUI();

}
Expand Up @@ -338,6 +338,18 @@ public JComponent getUI()
return view.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)
Expand Down

0 comments on commit 8965057

Please sign in to comment.