Changeset 4621 for trunk


Ignore:
Timestamp:
2003-06-12T18:04:22+12:00 (21 years ago)
Author:
kjdon
Message:

tried to make the custom thingy work - it kindof works if you only try to add one classifier for any metadata element. there are major problems with it - it should add the metadata to teh docs on save not when teh classifier is specified. it should remove old metadata for a changed classifier. classifiers with teh same base metadata should create differently named hidden metadata, and different hfiles - currently they all get put together and you end up with a huge mess.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/custom/CustomAZList.java

    r4614 r4621  
    6666    /** When this the control dialog is disposed, should we go ahead a add this custom AZ list (by processing all file records and building a new hierarchy)? */
    6767    private boolean process = false;
     68    /** are we currently processing?? */
     69    private boolean is_processing = false;
    6870    /** A reference to the Gatherer for access to the Collection and MetadataSetManager. */
    6971    private Gatherer gatherer = null;
     
    111113    public CustomAZList() {}
    112114    /** Constructor.
    113       * @param gatherer A reference to the <strong>Gatherer</strong>.
    114       */
     115     * @param gatherer A reference to the <strong>Gatherer</strong>.
     116     */
    115117    public CustomAZList(Gatherer gatherer) {
    116118    this.gatherer = gatherer;
    117119    }
    118120    /** Used to compare this classifier to another classifier for the purposes of ordering.
    119       * @param object The other classifier as an <strong>Object</strong>.
    120       * @see org.greenstone.gatherer.cdm.Classifier
    121       * @see org.greenstone.gatherer.cdm.CustomClassifier
    122       */
     121     * @param object The other classifier as an <strong>Object</strong>.
     122     * @see org.greenstone.gatherer.cdm.Classifier
     123     * @see org.greenstone.gatherer.cdm.CustomClassifier
     124     */
    123125    public int compareTo(Object object) {
    124126    if(object instanceof Classifier) {
     
    136138    controls = null;
    137139    }
     140    public void hide() {
     141    controls.setVisible(false);
     142    }
    138143    /** Produce a new copy of this custom classifier. Remember that what the classifier manager does is create instances of all possible classifiers, then as they are assigned creates and assigns copies of the original reserve. This way we only have to parse arguments once.
    139       * @return A new <strong>CustomClassifier</strong> which is a copy of this one.
    140       * @see org.greenstone.gatherer.Gatherer
    141       */
     144     * @return A new <strong>CustomClassifier</strong> which is a copy of this one.
     145     * @see org.greenstone.gatherer.Gatherer
     146     */
    142147    public CustomClassifier copy() {
    143148    return new CustomAZList(gatherer);
     
    158163    public boolean display(boolean show) {
    159164    if(controls == null) {
     165       
    160166        Vector elements = gatherer.c_man.getCollection().msm.getAssignedElements();
    161167        // Creation
     
    191197        ok = new JButton(get("OK_JButton"));
    192198        cancel = new JButton(get("Cancel_JButton"));
    193                 // Connection
     199        // Connection
    194200        buttonname_label.addActionListener(new ButtonNameListener());
    195201        cancel.addActionListener(new CancelListener());
    196202        ok.addActionListener(new OKListener());
    197203        sort_label.addActionListener(new SortListener());
    198                 // The Toggle Button block. Done all at once so we don't end up with three for loops.
     204        // The Toggle Button block. Done all at once so we don't end up with three for loops.
    199205        JPanel center_pane = new JPanel();
    200206        center_pane.setLayout(new GridLayout(3, 9));
     
    214220        }
    215221        separators_preview.setText(getPreview(true));
    216                 // Layout
     222        // Layout
    217223        metadata_pane.setBorder(BorderFactory.createEmptyBorder(1,0,1,0));
    218224        metadata_pane.setLayout(new BorderLayout());
     
    253259        content_pane.add(center_pane, BorderLayout.CENTER);
    254260        content_pane.add(lower_pane, BorderLayout.SOUTH);
    255                 // Display
     261        // Display
    256262        Dimension screen_size = Gatherer.config.screen_size;
    257263        controls.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
     
    269275        return true;
    270276        }
    271                 // We do everything -except- display the control.
     277        // We do everything -except- display the control.
    272278    }
    273279    else {
     280        // we already have the controls
    274281        process = false;
    275282        controls.setVisible(true);
     
    289296        CustomClassifier classifier = (CustomClassifier) object;
    290297        if(getCommand().equalsIgnoreCase(classifier.getCommand())) {
     298        //if (toString().equalsIgnoreCase(classifier.toString())) {
    291299        return true;
    292300        }
     
    320328    }
    321329    /** Retrieve the custom command, a command line that overrides and replaces some other 'actual' classifier.
    322       * @param index The number of the classifer this one is replacing.
    323       */
     330     * @param index The number of the classifer this one is replacing.
     331     */
    324332    public String getCustomCommand(int index) {
    325333    StringBuffer text = new StringBuffer("customclassifier ");
     
    342350      */
    343351    public void process(FileNode record) {
     352    is_processing = true;
    344353    ElementWrapper element = (ElementWrapper) metadata.getSelectedItem();
    345354    if(element != null) {
    346355        addMetadata(0L, record, element);
    347356    }
     357    is_processing = false;
    348358    }
    349359    /** Recreate a CustomAZList given several parameters including the real classifier created during custom design.
     
    401411        }
    402412        }
    403                 // Rebuild mappings hashtable for this pattern. Add it if not present.
     413        // Rebuild mappings hashtable for this pattern. Add it if not present.
    404414        GValueNode node = model.addValue(key);
    405                 // If the key is simple, ie "C", then add the mapping "C"->node
     415        // If the key is simple, ie "C", then add the mapping "C"->node
    406416        if(node == null) {
    407417        // Do nothing.
     
    410420        mappings.put(key, node);
    411421        }
    412                 // If the key is more complex, say "D-L", then we add mappings for all string values so "D"->node, "E"->node, ... "L"->node. This is miles eaiser to do here, than when you are trying to match a records metadata ie matchin "D-L" to "Igloos are cool". Note that it is guarantee that the keys are all of the same length, ie "A-L", "MA-ML", "MMA-STF", "STFA-ZZZZ".
     422        // If the key is more complex, say "D-L", then we add mappings for all string values so "D"->node, "E"->node, ... "L"->node. This is miles eaiser to do here, than when you are trying to match a records metadata ie matchin "D-L" to "Igloos are cool". Note that it is guarantee that the keys are all of the same length, ie "A-L", "MA-ML", "MMA-STF", "STFA-ZZZZ".
    413423        else {
    414424        String start = key.substring(0, key.indexOf("-"));
     
    553563    public void actionPerformed(ActionEvent event) {
    554564        process = false;
    555         controls.dispose();
     565       
     566        controls.setVisible(false);
    556567    }
    557568    }
     
    564575    public void actionPerformed(ActionEvent event) {
    565576        process = true;
    566         controls.dispose();
     577        controls.setVisible(false);
    567578    }
    568579    }
     
    604615    // 33% - Allocation of metadata to records, 33 / <number of files>.
    605616    // Hopefully the previous dialog should have already vanished (its dispose() caused by the process click).
     617    is_processing = true;
    606618    pd = new ProgressDialog("Custom Classifier Creation", "Preparing for operation.");
    607619    // Step 1: Create the new dummy element and add it if necessary.
    608620    pd.setText("Creating dummy metadata element.");
     621    ///ystem.out.println("Creating dummy metadata element.");
    609622    MetadataSet hidden_mds = gatherer.c_man.getCollection().msm.getSet(MetadataSetManager.HIDDEN);
    610623    Element hidden_e = hidden_mds.getElement(element.toString().replace('.','_'));
     
    622635    // Step 2: Remove any existing value tree for this element. Wastefull I know but I don't want to lag for too long, and this is the quickest way.
    623636    pd.setText("Removing any existing hierarchy.");
     637    ///ystem.out.println("Removing any existing hierarchy.");
    624638    if(found) {
    625639        hidden_mds.removeValueTree(hidden_mde);
     
    628642    // Step 3: Create a value tree for this element.
    629643    pd.setText("Creating new hierary root.");
     644    ///ystem.out.println("Creating new hierary root.");
    630645    GValueModel value_tree = gatherer.c_man.getCollection().msm.getValueTree(hidden_mde);
    631646    pd.increase(5, 5, 5);
    632647    // Step 4: Build the single level value hierarchy using state's value. Here a hashtable mapping string patterns to value nodes is built.
    633648    pd.setText("Creating separations.");
     649    ///ystem.out.println("Creating separations.");
    634650    StringTokenizer tokenizer = new StringTokenizer(state, ",");
    635651    int separator_count = tokenizer.countTokens();
     
    650666        }
    651667        }
    652                 // Each iteration.
     668        // Each iteration.
    653669        pd.increase(1, separator_count, 25);
    654670    }
    655671    // Step 5: Recurse the entire tree, adding the appropriate values where necessary (overwriting any existing value for this element).
    656672    pd.setText("Allocating metadata to records.");
     673    ///ystem.out.println("Allocating metadata to records.");
    657674    int count = gatherer.c_man.getCollection().getCount();
    658675    TreeModel record_tree = gatherer.c_man.getRecordSet();
     
    670687        }
    671688        if(!current_record.isLeaf()) {
     689        ///ystem.out.println("Add all children to records at once hopefully.");
    672690        // Add all children to records at once hopefully.
    673691        FileNode children[] = new FileNode[current_record.getChildCount()];
     
    680698        pd.increase(1, count, 50);
    681699    }
     700    is_processing = false;
    682701    // Step 6: Done.
    683702    pd.dispose();
     
    685704    }
    686705
    687     public boolean valueIsAdjusting() {
    688     return (pd == null);
     706    public boolean isProcessing() {
     707    return is_processing;
    689708    }
    690709
     
    709728        setSize(dialog_size);
    710729        setTitle(t);
    711                 // Create
     730        // Create
    712731        JPanel content_pane = (JPanel) getContentPane();
    713732        label.setText(l);
     
    715734        bar.setMinimum(0);
    716735        bar.setValue(0);
    717                 // Connect
    718                 // Layout
     736        // Connect
     737        // Layout
    719738        content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    720739        content_pane.setLayout(new BorderLayout());
    721740        content_pane.add(label, BorderLayout.NORTH);
    722741        content_pane.add(bar, BorderLayout.CENTER);
    723                 // Display
     742        // Display
    724743        Dimension screen_size = Gatherer.config.screen_size;
    725744        setLocation((screen_size.width - dialog_size.width) / 2, (screen_size.height - dialog_size.height) / 2);
     
    728747    }
    729748    /** Increase the progress bar by a certain ammount.
    730             * @param item An <i>int</i> indicating what item number this is.
    731             * @param out_of An <i>int</i> detailing the number of items expected in total for this phase.
    732             * @param total The maximum value of the progress bar as an <i>int</i>.
    733             */
     749     * @param item An <i>int</i> indicating what item number this is.
     750     * @param out_of An <i>int</i> detailing the number of items expected in total for this phase.
     751     * @param total The maximum value of the progress bar as an <i>int</i>.
     752     */
    734753    public void increase(int item, int out_of, int total) {
    735754        value = value + (((double) item / (double) out_of) * (double)total);
     
    741760    }
    742761    /** Set the message shown in the progress bar.
    743             * @param l The new progress bar label as a <strong>String</strong>.
    744             */
     762     * @param l The new progress bar label as a <strong>String</strong>.
     763     */
    745764    public void setText(String l) {
    746765        label.setText(l);
Note: See TracChangeset for help on using the changeset viewer.