Project

General

Profile

« Previous | Next » 

Revision 8f3316f4

Added by Katja Luther over 3 years ago

fix problems with column index of distribution editor when changing areas

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/ChecklistEditorE4.java
198 198
        TableViewerEditor.create(viewer, focusCellManager, new ColumnViewerEditorActivationStrategy(viewer), TableViewerEditor.DEFAULT);
199 199

  
200 200

  
201
//        viewer.addSelectionChangedListener(new ISelectionChangedListener() {
202
//        	  @Override
203
//        	  public void selectionChanged(SelectionChangedEvent event) {
204
//        	    IStructuredSelection selection = viewer.getStructuredSelection();
205
//        	    Object firstElement = selection.getFirstElement();
206
//        	    // do something with it
207
//        	  }
208
//
209
//
210
//        	});
201

  
211 202

  
212 203

  
213 204

  
214 205
        labelProvider = new ChecklistLabelProvider(this);
215
       // SortedSet<DefinedTermBase> termSet = labelProvider.getNamedAreas(true);
216
//        terms = new HashMap();
217
//        for (DefinedTermBase term : termSet){
218
//                terms.put(term.getUuid(), term);
219
//        }
220
//        if (terms == null){
221
//			MessagingUtils.informationDialog(Messages.ChecklistEditor_NO_AREAS, Messages.ChecklistEditor_NO_AREAS_MESSAGE);
222
//			this.dispose();
223
//			return;
224
//		}
206

  
225 207

  
226 208

  
227 209
        viewer.addFilter(filter);
......
290 272
     */
291 273
    private Text createSearchBar(Composite parent) {
292 274

  
293

  
294

  
295
//        FillLayout fillLayout = new FillLayout();
296
//
297
//        fillLayout.type = SWT.VERTICAL;
298
//        parent.setLayoutData(fillLayout);
299
//        Label searchLabel = new Label(parent, SWT.NONE);
300
//        searchLabel.setText(Messages.ChecklistEditor_SEARCH);
301
//        GridData gridDataLabel = new GridData();
302
//        gridDataLabel.horizontalSpan =1;
303
//        searchLabel.setLayoutData(gridDataLabel);
304 275
        final Text searchText = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.CANCEL);
305 276
        GridData gridData = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
306 277

  
......
376 347

  
377 348
        toolItem.setText(Messages.ChecklistEditor_DIST_STATUS);
378 349
        toolItem.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP);
379
        //createToolbarItems();
380
      //  toolItem.addSelectionListener(dropListener);
350

  
381 351
        toolItem.addSelectionListener(new SelectionAdapter() {
382 352
            @Override
383 353
            public void widgetSelected(SelectionEvent event) {
......
422 392
        statusLabel.setLayoutData(gridData);
423 393

  
424 394
        statusLabelSourceReference = new Label(composite, SWT.RIGHT);
425
//        GridData sourceGrid = new GridData();
426
//        sourceGrid.horizontalAlignment = GridData.HORIZONTAL_ALIGN_END;
427
//        //sourceGrid.grabExcessHorizontalSpace = false;
428
//        sourceGrid.horizontalSpan = 1;
395

  
429 396
       statusLabelSourceReference.setLayoutData(gridData);
430 397

  
431 398
        if (defaultSource != null){
......
468 435
	private void createInitalDistributionColumns(Table table,
469 436
			List<String> titles, List<Integer> bounds) {
470 437
		for (int columnIndex = 0; columnIndex < titles.size(); columnIndex++) {
471
            TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
472
            column.getColumn().setText(titles.get(columnIndex));
473
            column.getColumn().setWidth(bounds.get(columnIndex));
474
            column.getColumn().setResizable(true);
475
            column.getColumn().setMoveable(true);
476
            column.getColumn().addSelectionListener(getSelectionAdapter(column.getColumn(), columnIndex));
438
		    final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.FULL_SELECTION);
439
	        final TableColumn column = viewerColumn.getColumn();
440
//            TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
441
            column.setText(titles.get(columnIndex));
442
            column.setWidth(bounds.get(columnIndex));
443
            column.setResizable(true);
444
            column.setMoveable(true);
445
            column.addSelectionListener(getSelectionAdapter(column, columnIndex));
477 446
            if (columnIndex == 0) {
478
                table.setSortColumn(column.getColumn());
447
                table.setSortColumn(column);
479 448
            }
480 449
            if (columnIndex == 1 && PreferencesUtil.isShowRankInChecklistEditor()) {
481 450
            	/** uncommented it for now because no rank editing is wanted **/
......
484 453
            if ((columnIndex == 1 && !PreferencesUtil.isShowRankInChecklistEditor()) || columnIndex >= 2 ) {
485 454
                //read PrefrenceStore to setWidth according to last saved state
486 455
//                if(restoreValuesForColumnWidth.get(columnIndex)){
487
                    column.getColumn().setWidth(50);
456
                    column.setWidth(50);
488 457
//                }else{
489 458
//                    column.getColumn().setWidth(0);
490 459
//                }
491
                column.setEditingSupport(new DistributionEditingSupportE4(viewer, this, columnIndex));
460
                    viewerColumn.setEditingSupport(new DistributionEditingSupportE4(viewer, this, columnIndex));
492 461

  
493 462
            }
494 463
        }
......
561 530
     */
562 531
    private TableViewerColumn addTableViewerColumn(String title, int bound, final int colNumber, DefinedTermBase term) {
563 532

  
564
        final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.FULL_SELECTION);
533
        final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.FULL_SELECTION, colNumber);
534

  
565 535
        final TableColumn column = viewerColumn.getColumn();
566 536
        column.setText(title);
567 537
        String[] UuidAndLable = new String[2];
......
570 540
        column.setData(UuidAndLable);
571 541
        column.setWidth(200);
572 542

  
543

  
573 544
        viewerColumn.setEditingSupport(new DistributionEditingSupportE4(viewer, this, colNumber));
574 545
        column.setResizable(true);
575
        column.setMoveable(true);
546
        column.setMoveable(false);
576 547
        return viewerColumn;
577 548
      }
578 549

  
......
692 663
//    	    terms = (SortedSet<DefinedTermBase>) labelProvider.getTermsOrderedByLabels(labelProvider.getNamedAreas(), CdmStore.getDefaultLanguage());
693 664
//    	}
694 665
    	SortedSet<DefinedTermBase> newTerms = labelProvider.getNamedAreas(true);
695
    	//terms = newTerms;
696
//    	toolItem.removeSelectionListener(dropListener);
697
////    	hideDistributionColumns(oldTerms);
698
//    	createToolbarItems();
699
//    	toolItem.addSelectionListener(dropListener);
666

  
700 667

  
701 668
    	//check which terms are deleted and which are new.
702 669
    	TableColumn[] columns = viewer.getTable().getColumns() ;
......
708 675
            }
709 676
          index++;
710 677
      }
711
      if (oldTerms != null){
712
    	for (DefinedTermBase oldTerm:oldTerms){
713
            boolean delete = true;
714
            for (DefinedTermBase term: newTerms){
715
                   if(oldTerm.getUuid().equals(term.getUuid())){
716
                       delete = false;
717
                       break;
718
                   }
719

  
720
            }
721
            if (delete){
722
               // viewer.getTable().remove(areaPosition.get(oldTerm.getUuid()));
723
                areaPosition.remove(oldTerm.getUuid());
724 678

  
725
            }
726
        }
727
    	updateColumnIndex();
679
      areaPosition.clear();
680
      int columnIndex;
681
      if (PreferencesUtil.isShowRankInChecklistEditor()){
682
          columnIndex = 2;
683
      } else{
684
          columnIndex = 1;
685
      }
686
      for (DefinedTermBase term:newTerms){
687
          areaPosition.put(term.getUuid(), Integer.valueOf(columnIndex));
688
          columnIndex++;
728 689
      }
729 690

  
691
      for (DefinedTermBase term: newTerms){
692
          Representation rep = term.getPreferredRepresentation(CdmStore.getDefaultLanguage());
693

  
694
          String termLable = rep.getAbbreviatedLabel();
695
          if (termLable == null){
696
              termLable = rep.getLabel();
697
          }
698
          if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
699
              if (term.getIdInVocabulary() != null){
700
                termLable = term.getIdInVocabulary();
701
              }
702
          }
703
    	  TableViewerColumn column= addTableViewerColumn(termLable, 200, areaPosition.get(term.getUuid()), term);
704
    	  System.err.println(column.getColumn().getText() + " index: " +areaPosition.get(term.getUuid()) );
730 705

  
731
    	for (DefinedTermBase term:newTerms){
732
    	    boolean isNew = true;
733

  
734
    	    Integer position = areaPosition.get(term.getUuid());
735
    	    Representation rep = term.getPreferredRepresentation(CdmStore.getDefaultLanguage());
736

  
737
    	    String termLable = rep.getAbbreviatedLabel();
738
    	    if (termLable == null){
739
    	        termLable = rep.getLabel();
740
    	    }
741
            if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
742
                if (term.getIdInVocabulary() != null){
743
                    termLable = term.getIdInVocabulary();
744
                }
745
            }
746

  
747
            if (position == null){
748
                int count = viewer.getTable().getColumnCount();
749
                TableViewerColumn column= addTableViewerColumn(termLable, 200, count, term);
750
                areaPosition.put(term.getUuid(), Integer.valueOf(count));
751
            }else{
752
                TableViewerColumn column= addTableViewerColumn(termLable, 200, position, term);
753
            }
754

  
755

  
756
    	}
757

  
758
        viewer.setLabelProvider(labelProvider);
706
      }
759 707

  
760
        table.setRedraw(true);
761
    	viewer.refresh();
708
      viewer.setLabelProvider(labelProvider);
709
      table.setRedraw(true);
710
      viewer.refresh();
762 711
    }
763 712

  
764 713
	/**
......
813 762

  
814 763
    public void doSave(IProgressMonitor monitor) {
815 764
        try {
816
          //  monitor.beginTask(Messages.ChecklistEditor_SAVE_EDITOR, 1);
817
//            if (!conversation.isBound()) {
818
//                conversation.bind();
819
//            }
820 765

  
821 766
            this.checklistEditorInput.merge();
822 767

  
823
            //conversation.commit(true);
768

  
824 769
            setDirty(false);
825
  //          monitor.worked(1);
770

  
826 771
        } finally {
827
   //         monitor.done();
772

  
828 773
        }
829 774

  
830 775
    }

Also available in: Unified diff