Changeset 6394


Ignore:
Timestamp:
2004-01-09T15:17:29+13:00 (20 years ago)
Author:
jmt12
Message:

As part of setting up modes we also added the ability to programatically access the MEM from within design view

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/mem/MetadataEditorManager.java

    r6318 r6394  
    7373public class MetadataEditorManager
    7474    extends ModalDialog {
     75    static final public int ADD_SET    = 0;
     76    static final public int NORMAL     = 1;
     77    static final public int REMOVE_SET = 2;
     78    /** The default size of the editor dialog. */
     79    static final private Dimension ADD_ELEMENT_SIZE = new Dimension(400,125);
     80    static final private Dimension ADD_FILE_SIZE = new Dimension(400,125);
     81    static final private Dimension ADD_SET_SIZE = new Dimension(400,125);
     82    static final private Dimension ADD_OR_EDIT_ATTRIBUTE_SIZE = new Dimension(600,325);
     83    static final private Dimension ADD_OR_EDIT_VALUE_SIZE = new Dimension(600,440);
     84    static final private Dimension LABEL_SIZE = new Dimension(100,30);
     85    static final private Dimension SIZE = new Dimension(800,480);
     86    static final private String BLANK = "blank";
     87    static final private String ELEMENT = "element";
     88    static final private String PROFILE = "profile";
     89    static final private String SET = "set";
     90    static final private String VALUES = "values";
     91
    7592    private AddElementActionListener add_element_action_listener = null;
    7693    private AddFileActionListener add_file_action_listener = null;
     
    119136    private MetadataSet current_set = null;
    120137    private Object target = null;
     138    private RemoveSetActionListener remove_set_action_listener;
    121139    private SmarterTable element_attributes = null;
    122140    private SmarterTable profile_attributes = null;
     
    127145    private String current_collection_file = null;
    128146    private String dialog_options[] = null;
    129     /** The default size of the editor dialog. */
    130     static final private Dimension ADD_ELEMENT_SIZE = new Dimension(400,125);
    131     static final private Dimension ADD_FILE_SIZE = new Dimension(400,125);
    132     static final private Dimension ADD_SET_SIZE = new Dimension(400,125);
    133     static final private Dimension ADD_OR_EDIT_ATTRIBUTE_SIZE = new Dimension(600,325);
    134     static final private Dimension ADD_OR_EDIT_VALUE_SIZE = new Dimension(600,440);
    135     static final private Dimension LABEL_SIZE = new Dimension(100,30);
    136     static final private Dimension SIZE = new Dimension(800,480);
    137     static final private String BLANK = "blank";
    138     static final private String ELEMENT = "element";
    139     static final private String PROFILE = "profile";
    140     static final private String SET = "set";
    141     static final private String VALUES = "values";
    142     /** Constructor. */
    143     public MetadataEditorManager() {
     147
     148    /** Constructor.
     149     * @param set a MetadataSet that should be initially selected
     150     * @param action a systematic action that should be performed
     151     */
     152    public MetadataEditorManager(MetadataSet set, int action) {
    144153    super(Gatherer.g_man);
    145154    this.dialog_options = new String[2];
     
    175184    mds_tree.setSelectionColor(Gatherer.config.getColor("coloring.collection_selection_background", false));
    176185    mds_tree.setSelectedTextColor(Gatherer.config.getColor("coloring.collection_selection_foreground", false));
     186    // We may have been asked to select a cetain initial set
     187    if(set != null) {
     188        MEMNode root = (MEMNode) model.getRoot();
     189        for(int i = 0; i < root.getChildCount(); i++) {
     190        MEMNode child = (MEMNode) root.getChildAt(i);
     191        if(set.equals(child.getUserObject())) {
     192            TreePath path = new TreePath(child.getPath());
     193            mds_tree.setSelectionPath(path);
     194            mds_tree.expandPath(path);
     195            path = null;
     196        }
     197        child = null;
     198        }
     199        root = null;
     200    }
    177201
    178202    details_pane = new JPanel();
     
    363387    add_or_edit_attribute_action_listener = new AddOrEditAttributeActionListener();
    364388    add_or_edit_value_action_listener = new AddOrEditValueActionListener();
     389    remove_set_action_listener = new RemoveSetActionListener();
    365390
    366391    // Some blank panel
     
    386411    remove_element.addActionListener(new RemoveElementActionListener());
    387412    remove_file.addActionListener(new RemoveFileActionListener());
    388     remove_set.addActionListener(new RemoveSetActionListener());
     413    remove_set.addActionListener(remove_set_action_listener);
    389414    remove_value.addActionListener(new RemoveValueActionListener());
    390415    element_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(element_attributes));
     
    499524    content_pane.add(button_pane, BorderLayout.SOUTH);
    500525
     526    // Callback - we may have been asked to perform some systematic action, but we can't do that until the dialog is visible, which in itself causes a problem as the dialog is modal and setVisible won't return until the dialog is cancelled. The solution is to spawn a task on a new thread which waits until the dialog is visible then calls doClick on the appropriate button.
     527    if(action != NORMAL) {
     528        ActionTask task = new ActionTask(action);
     529        task.start();
     530    }
    501531    // Display
    502532    setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
     
    504534    }
    505535     
     536    private class ActionTask
     537    extends Thread {
     538    private int action;
     539    public ActionTask(int action) {
     540        this.action = action;
     541    }
     542    public void run() {
     543        boolean complete = false;
     544        while(!complete) {
     545        if(self.isVisible()) {
     546            switch(action) {
     547            case ADD_SET:
     548            add_set_action_listener.actionPerformed(new ActionEvent(this, 0, "Blarg!"));
     549            break;
     550            case REMOVE_SET:
     551            if(!mds_tree.isSelectionEmpty()) {
     552                remove_set_action_listener.actionPerformed(new ActionEvent(this, 0, "Blarg!"));
     553            }
     554            break;
     555            }
     556            complete = true;
     557        }
     558        else {
     559            try {
     560            synchronized(this) {
     561                wait(100);
     562            }
     563            }
     564            catch(Exception exception) {
     565            }
     566        }
     567        }
     568    }
     569    }
     570
    506571    public void dispose() {
    507572    // Destructor
     
    544609        add_or_edit_value_action_listener = null;
    545610    }
     611    remove_set_action_listener = null;
    546612    super.dispose();
    547613    }
  • trunk/gli/src/org/greenstone/gatherer/msm/MetadataSetManager.java

    r6213 r6394  
    192192     * @return A boolean indicating if the edit was successful.
    193193     */
    194     public boolean editMDS() {
    195     MetadataEditorManager mem = new MetadataEditorManager();
     194    public boolean editMDS(MetadataSet set, int action) {
     195    MetadataEditorManager mem = new MetadataEditorManager(set, action);
    196196    mem.dispose();
    197197    mem = null;
Note: See TracChangeset for help on using the changeset viewer.