2011-06-28 9 views
1

hwoテーブルのデフォルトの選択動作を変更することができます。ユーザーがクリックするとセルを選択し、ダブルクリックすると編集可能にしたいと考えています。eclipse rcp:tableviewerで単一のセルを選択する方法は?

@nontyの助けを借りて、私は欲しいものを手に入れます。

package com.amarsoft.rcputil; 

import org.eclipse.jface.viewers.ColumnViewer; 
import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter; 
import org.eclipse.jface.viewers.ViewerCell; 
import org.eclipse.swt.SWT; 
import org.eclipse.swt.graphics.Color; 


public class DefaultCellFocusHighlighter extends FocusCellOwnerDrawHighlighter { 

    public DefaultCellFocusHighlighter(ColumnViewer viewer) { 
     super(viewer); 
    } 

    protected boolean onlyTextHighlighting(ViewerCell cell) { 
     return false; 
    } 

    protected Color getSelectedCellBackgroundColor(ViewerCell cell) { 
     return cell.getControl().getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE); 
    } 

    protected Color getSelectedCellForegroundColor(ViewerCell cell) { 
     return cell.getControl().getDisplay().getSystemColor(SWT.COLOR_WHITE); 
    } 

    protected Color getSelectedCellForegroundColorNoFocus(ViewerCell cell) { 
     return cell.getControl().getDisplay().getSystemColor(SWT.COLOR_WHITE); 
    } 

    protected Color getSelectedCellBackgroundColorNoFocus(ViewerCell cell) { 
     return cell.getControl().getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE); 
    } 

    protected void focusCellChanged(ViewerCell newCell, ViewerCell oldCell) { 
     super.focusCellChanged(newCell, oldCell); 
    } 



} 

それを使用するコード::ここ
enter image description here
は私の細胞蛍光ペンimplementionある

TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(tv,new DefaultCellFocusHighlighter(tv)); 
     ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(tv) { 
      protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) { 
       return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL 
         || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION 
         || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR) 
         || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC; 
      } 
     }; 

     TableViewerEditor.create(tv, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL 
       | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR 
       | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION); 

が、私は新しい問題だ:私は編集するセルをダブルクリックしたときに enter image description here
をそれは価値がある、セルの左側の小さな領域が濃い青色でまだ強調表示されている

理由:
境界線付きのテキストコントロールを作成すると、オペレーティングシステムには、コントロールのコンテンツの周りにプラットフォーム固有のインセットが含まれています。まだ固定するために求めている
...

答えて

1

は、これら二つのJFaceのスニペットを見てください:

  • Snippet036FocusBorderCellHighlighter - もう一度の柔軟性を示すフォーカス枠で現在選択されているセルを強調表示することにより、キーボードナビゲーションをデモ新しいセルナビゲーションサポート
  • Snippet034CellEditorPerRowNewAPIは - JFaceの-視聴者の3.3-APIと1列に異なるcellEditorを-タイプをデモ
+0

@nontyありがとう。私はこれらの2つのスニペットをチェックしましたが、Snippet036FocusBorderCellHighlighterでは、セルがクリックされたときにそのセルが再描画されて強調表示された外観が削除されましたが、同じ行の他のセルはまだ強調表示されています。私はそれができるようにデフォルトの選択の動作を無効にする可能性があると考えている、それを行うコードを書く。私はあなたがSWT.FULL_SELECTIONでテーブルを作成するときに、リスナーを付けずに行をクリックし、行が選択されていることを確認します。マウスイベントリスナーが基になるSWTテーブルで起動されている必要があります。 – CaiNiaoCoder

+0

@nonty多分私根底にあるlsitenerを削除して新しいlsitenerを追加できますか? – CaiNiaoCoder

+0

あなたが何を意味するのかわかりません - 158行目の 'FocusCellHighlighter'として' FocusCellOwnerDrawHighlighter'を使用してサンプルを実行すると、意図した動作が得られます... –

0

コードを掘り後、私はColumnViewerクラスに次のメソッドが見つかりました:

/** 
* Hook up the editing support. Subclasses may override. 
* 
* @param control 
*  the control you want to hook on 
*/ 
protected void hookEditingSupport(Control control) { 
    // Needed for backwards comp with AbstractTreeViewer and TableTreeViewer 
    // who are not hooked this way others may already overwrite and provide 
    // their 
    // own impl 
    if (viewerEditor != null) { 
     control.addMouseListener(new MouseAdapter() { 
      public void mouseDown(MouseEvent e) { 
       // Workaround for bug 185817 
       if (e.count != 2) { 
        handleMouseDown(e); 
       } 
      } 

      public void mouseDoubleClick(MouseEvent e) { 
       handleMouseDown(e); 
      } 
     }); 
    } 
} 

だから、私は私のTableViewerのサブクラス内、その関数をオーバーライド:

@Override protected void hookEditingSupport(Control control) { 
    // We know there should be an editor avaiable 
// if (viewerEditor != null) { 
     control.addMouseListener(new MouseAdapter() { 
      public void mouseDown(MouseEvent e) { 
       // Workaround for bug 185817 
       if (e.count != 2) { 
        // We don't want to edit on single clicks 
//     handleMouseDown(e); 
       } 
      } 

      public void mouseDoubleClick(MouseEvent e) { 
       // This method is private, so copy the implementation 
//    handleMouseDown(e); 
       ViewerCell cell = getCell(new Point(e.x, e.y)); 
       e.count--; // A hack to make things work - pretend like it's a single click 
       if (cell != null) { 
        triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(
          cell, e)); 
       } 
      } 
     }); 
// } 
} 

これは私のために動作します。それがあなたのために働くかどうか教えてください。

関連する問題