Revision 3606

View differences:

trunk/applications/appCatalogYNomenclatorClient/src/es/gva/cit/catalogClient/ui/search/SearchDialogPanel.java
40 40
*   dac@iver.es
41 41
*/
42 42
package es.gva.cit.catalogClient.ui.search;
43
import java.awt.Cursor;
43 44
import java.awt.Dimension;
44 45
import java.awt.FlowLayout;
45 46
import java.awt.event.ActionEvent;
......
123 124
 * 
124 125
 * 
125 126
 */
127
    private JButton cancelSearchesButton = null;
128
/**
129
 * 
130
 * 
131
 */
126 132
    private JButton sizeButton = null;
127 133
/**
128 134
 * 
......
152 158
 * 
153 159
 */
154 160
    private ITranslator translator = null;
155

  
156 161
/**
162
 * 
163
 * 
164
 */
165
   private Collection searchThreads = null;
166
    
167
/**
157 168
 * This method initializes
158 169
 * 
159 170
 * 
......
163 174
 */
164 175
    public  SearchDialogPanel(JFrame parent, ITranslator translator, CatalogClient client) {        
165 176
        super();
177
        searchThreads = new java.util.ArrayList();
166 178
        this.isMinimized = true;
167 179
        this.parent = parent;
168 180
        this.translator = translator;
......
179 191
        ppalPanel = new JPanel();
180 192
        ppalPanel.setLayout(new BoxLayout(ppalPanel, BoxLayout.Y_AXIS));
181 193
        ppalPanel.add(getUpperPanel());
182
        ppalPanel.add(getLowerPanel());
183
        
194
        ppalPanel.add(getLowerPanel());        
184 195
        ppalPanel.add(getButtonsPanel());
185 196
        add(ppalPanel);
186 197
        setDefaultButtonListeners();
......
233 244
        if (buttonsPanel == null) {
234 245
            buttonsPanel = new JPanel(new FlowLayout());
235 246
            buttonsPanel.add(getSearchButton());
247
            buttonsPanel.add(getCancelSearchesButton());
236 248
            buttonsPanel.add(getCloseButton());
237 249
        }
238 250
        return buttonsPanel;
......
252 264
        }
253 265
        return searchButton;
254 266
    } 
267
    
268
/**
269
 * It gets the cancel searches button
270
 * 
271
 * 
272
 * @return 
273
 */
274
    public JButton getCancelSearchesButton() {        
275
        if (cancelSearchesButton == null) {
276
            cancelSearchesButton = new JButton(Translator.getText(translator,"cancelSearchButton"));
277
            cancelSearchesButton.setSize(new Dimension(30, 20));
278
            cancelSearchesButton.setActionCommand("cancel");
279
        }
280
        return cancelSearchesButton;
281
    } 
255 282

  
256 283
/**
257 284
 * It gets the close button
......
305 332
        getCloseButton().addActionListener(this);
306 333
        getSizeButton().addActionListener(this);
307 334
        getAreaCheckBox().addItemListener(this);
335
        getCancelSearchesButton().addActionListener(this);
308 336
    } 
309
/* (non-Javadoc)
310
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
311
     */
312

  
313 337
/**
314 338
 * 
315 339
 * 
......
326 350
        }
327 351
        if (e.getActionCommand() == "size") {
328 352
            sizeButtonActionPerformed();
329
        }     
330
        
353
        }             
354
        if (e.getActionCommand() == "cancel") {
355
            cancelSearchesButtonActionPerformed();
356
        }           
331 357
    } 
332 358

  
333 359
/**
......
354 380
 * 
355 381
 */
356 382
    protected void searchButtonActionPerformed() {        
357
        new searchThread().start();
383
        searchThread st =  new searchThread();
384
        searchThreads.add(st);   
385
        setCursor(new Cursor(Cursor.WAIT_CURSOR));        
358 386
    } 
387
    
388
/**
389
 * 
390
 * 
391
 */
392
    protected void cancelSearchesButtonActionPerformed() {        
393
        for (int i=0 ; i<searchThreads.size() ; i++){
394
            searchThread st = (searchThread)searchThreads.toArray()[i];
395
            st.stop();            
396
        }     
397
        searchThreads.clear();
398
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));        
399
    }    
359 400

  
360 401
/**
361 402
 * 
......
398 439
 * This method realizes the search
399 440
 * 
400 441
 */
401
    protected void doSearch() {        
442
    private void doSearch() {        
402 443
        nodes = client.getRecords(client.getUrl(),
403 444
                doQuery(), 1);
404 445
        if (nodes == null) {
......
420 461
 * 
421 462
 * @param nodes 
422 463
 */
423
    protected void showResults(Collection nodes) {        
464
    private void showResults(Collection nodes) {        
424 465
       new ShowResultsDialog(client, nodes, 1);
425 466
    } 
426 467
/* (non-Javadoc)
......
480 521
    } 
481 522
    
482 523
    /**
483
     * This class is used to do a search like a thread
524
     * This class is used to manage the searches.
525
     * It contains method to start and to stop a thread. It is
526
     * necessary to create because "stop" method (for the Thread class)
527
     * is deprecated.
484 528
     * @author Jorge Piera Llodra (piera_jor@gva.es)
485 529
     */
486
    private class searchThread extends Thread{
530
    private class searchThread implements Runnable{
531
        volatile Thread myThread = null;        
532
       
487 533
        public searchThread(){
488
          
534
            myThread = new Thread(this);
535
            myThread.start();
489 536
        }
490
        /**
491
         * This method executes the thread tasks
492
         */
493
        public void run(){
537
       
538
        
539
        public void stop(){
540
            myThread.stop();
541
        }
542
      
543
        public void run() {
494 544
            doSearch();
495 545
            if ((nodes != null) && (nodes.size() > 1)) {
496
                showResults(nodes);
546
                 showResults(nodes);
497 547
            }
498
        }
548
            searchThreads.remove(this);
549
            if (searchThreads.size() == 0){
550
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));       
551
            }
552
       }
553
        
499 554
    }
500 555
 }
trunk/applications/appCatalogYNomenclatorClient/text.properties
105 105
goto=Hacer un zoom a la b?squeda
106 106
aspect=Configuracion de aspecto
107 107
unknown=Desconocido
108
cancelSearchButton=Cancelar
108 109

  

Also available in: Unified diff