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); UIUtilities.unifiedButtonLookAndFeel(removeTagsButton);
removeTagsButton.setBackground(UIUtilities.BACKGROUND_COLOR); removeTagsButton.setBackground(UIUtilities.BACKGROUND_COLOR);
removeTagsButton.setToolTipText("Unlink Tags."); removeTagsButton.setToolTipText("Unlink Tags.");
removeTagsButton.addActionListener(controller); removeTagsButton.addMouseListener(controller);
//removeTagsButton.addActionListener(controller);
removeTagsButton.setActionCommand(""+EditorControl.REMOVE_TAGS); removeTagsButton.setActionCommand(""+EditorControl.REMOVE_TAGS);
removeDocsButton = new JButton(icons.getIcon(IconManager.MINUS_12)); removeDocsButton = new JButton(icons.getIcon(IconManager.MINUS_12));
UIUtilities.unifiedButtonLookAndFeel(removeDocsButton); UIUtilities.unifiedButtonLookAndFeel(removeDocsButton);
removeDocsButton.setBackground(UIUtilities.BACKGROUND_COLOR); removeDocsButton.setBackground(UIUtilities.BACKGROUND_COLOR);
removeDocsButton.setToolTipText("Unlink Attachments."); removeDocsButton.setToolTipText("Unlink Attachments.");
removeDocsButton.addActionListener(controller); //removeDocsButton.addActionListener(controller);
removeDocsButton.addMouseListener(controller);
removeDocsButton.setActionCommand(""+EditorControl.REMOVE_DOCS); removeDocsButton.setActionCommand(""+EditorControl.REMOVE_DOCS);


selectedValue = 0; selectedValue = 0;
Expand Down Expand Up @@ -1239,6 +1241,54 @@ List<TagAnnotationData> removeTags()
return list; 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. * Overridden to set the title of the component.
* @see AnnotationUI#getComponentTitle() * @see AnnotationUI#getComponentTitle()
Expand Down
Expand Up @@ -29,6 +29,10 @@
import java.awt.Point; import java.awt.Point;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; 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.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.io.File; import java.io.File;
Expand All @@ -39,8 +43,11 @@
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Map.Entry; import java.util.Map.Entry;

import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JTabbedPane; import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.filechooser.FileFilter; 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.TIFFFilter;
import org.openmicroscopy.shoola.util.filter.file.WordFilter; import org.openmicroscopy.shoola.util.filter.file.WordFilter;
import org.openmicroscopy.shoola.util.filter.file.XMLFilter; 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.UIUtilities;
import org.openmicroscopy.shoola.util.ui.filechooser.FileChooser; import org.openmicroscopy.shoola.util.ui.filechooser.FileChooser;
import org.openmicroscopy.shoola.util.ui.omeeditpane.OMEWikiComponent; import org.openmicroscopy.shoola.util.ui.omeeditpane.OMEWikiComponent;
Expand All @@ -106,7 +114,7 @@
* @since OME3.0 * @since OME3.0
*/ */
class EditorControl class EditorControl
implements ActionListener, ChangeListener, PropertyChangeListener implements ActionListener, ChangeListener, PropertyChangeListener, MouseListener
{ {


/** Bound property indicating that the save status has been modified. */ /** 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: case RELOAD_SCRIPT:
view.reloadScript(); view.reloadScript();
break; break;
/*
case REMOVE_TAGS: case REMOVE_TAGS:
view.removeTags(); view.removeTags();
break; break;
case REMOVE_DOCS: case REMOVE_DOCS:
view.removeAttachedFiles(); view.removeAttachedFiles();
break; break;
*/
case SAVE_AS: case SAVE_AS:
saveAsJPEG(); 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.Set;
import java.util.Map.Entry; import java.util.Map.Entry;


import javax.swing.JFrame;

//Third-party libraries //Third-party libraries


//Application-internal dependencies //Application-internal dependencies
Expand Down Expand Up @@ -2818,5 +2820,11 @@ boolean isLargeImage()
return false; 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.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Point; import java.awt.Point;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
Expand All @@ -54,6 +55,7 @@
import org.openmicroscopy.shoola.env.data.model.ScriptObject; import org.openmicroscopy.shoola.env.data.model.ScriptObject;
import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.env.event.EventBus;
import org.openmicroscopy.shoola.env.rnd.RenderingControl; import org.openmicroscopy.shoola.env.rnd.RenderingControl;
import org.openmicroscopy.shoola.util.ui.MessageBox;
import org.openmicroscopy.shoola.util.ui.UIUtilities; import org.openmicroscopy.shoola.util.ui.UIUtilities;
import pojos.AnnotationData; import pojos.AnnotationData;
import pojos.DataObject; 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. * 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 (!generalPane.hasAttachmentsToUnlink()) return;
if (list.size() > 0) saveData(true); 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(); 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. * Removes the annotation from the view.
* *
Expand Down
Expand Up @@ -34,6 +34,7 @@
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JFrame;


//Third-party libraries //Third-party libraries


Expand Down Expand Up @@ -619,4 +620,11 @@ public void setThumbnails(Map<Long, BufferedImage> thumbnails,
*/ */
void onGroupSwitched(boolean success); 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(); 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. * Implemented as specified by the {@link MetadataViewer} interface.
* @see MetadataViewer#setRootObject(Object, long) * @see MetadataViewer#setRootObject(Object, long)
Expand Down

0 comments on commit 8965057

Please sign in to comment.