org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent Java Examples

The following examples show how to use org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GalleryTreeViewer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public void editElement(Object element, int column) {
	if (element instanceof TreePath) {
		setSelection(new TreeSelection((TreePath) element));
		GalleryItem[] items = gallery.getSelection();

		if (items.length == 1) {
			ViewerRow row = getViewerRowFromItem(items[0]);

			if (row != null) {
				ViewerCell cell = row.getCell(column);
				if (cell != null) {
					getControl().setRedraw(false);
					triggerEditorActivationEvent(
							new ColumnViewerEditorActivationEvent(cell));
					getControl().setRedraw(true);
				}
			}
		}
	} else {
		super.editElement(element, column);
	}
}
 
Example #2
Source File: GridTableViewer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void editElement(Object element, int column) {
    try {
        getControl().setRedraw(false);
        Widget item = findItem(element);
        if (item != null) {
            ViewerRow row = getViewerRowFromItem(item);
            if (row != null) {
                ViewerCell cell = row.getCell(column);
                if (cell != null) {
                    triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell));
                }
            }
        }
    } finally {
        getControl().setRedraw(true);
    }
    // }
}
 
Example #3
Source File: GridViewerEditor.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void updateFocusCell(ViewerCell focusCell, ColumnViewerEditorActivationEvent event) {
	Grid grid = ((Grid)getViewer().getControl());

	if (event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC
			|| event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL) {
		grid.setFocusColumn(grid.getColumn(focusCell.getColumnIndex()));
		grid.setFocusItem((GridItem) focusCell.getItem());
		
		if( selectionFollowsEditor ) {
			grid.setCellSelection(new Point(focusCell.getColumnIndex(),((GridItem)focusCell.getItem()).getRowIndex()));
		}
	}
			
	grid.showColumn(grid.getColumn(focusCell.getColumnIndex()));
	grid.showItem((GridItem) focusCell.getItem()); 
}
 
Example #4
Source File: CTreeComboViewer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/** 
 * @see org.eclipse.jface.viewers.ColumnViewer#editElement(java.lang.Object, int)
 */
public void editElement(Object element, int column) {
	if (element instanceof TreePath) {
		try {
			getControl().setRedraw(false);
			setSelection(new TreeSelection((TreePath) element));
			CTreeComboItem[] items = tree.getSelection();

			if (items.length == 1) {
				ViewerRow row = getViewerRowFromItem(items[0]);

				if (row != null) {
					ViewerCell cell = row.getCell(column);
					if (cell != null) {
						triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell));
					}
				}
			}
		} finally {
			getControl().setRedraw(true);
		}
	} else {
		super.editElement(element, column);
	}
}
 
Example #5
Source File: GridTableViewer.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void editElement(Object element, int column) {
	try {
		getControl().setRedraw(false);
		Widget item = findItem(element);
		if (item != null) {
			ViewerRow row = getViewerRowFromItem(item);
			if (row != null) {
				ViewerCell cell = row.getCell(column);
				if (cell != null) {
					triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(
							cell));
				}
			}
		}
	} finally {
		getControl().setRedraw(true);
	}
	// }
}
 
Example #6
Source File: GridViewerEditor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected void updateFocusCell(ViewerCell focusCell, ColumnViewerEditorActivationEvent event) {
	Grid grid = ((Grid)getViewer().getControl());

	if (event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC
			|| event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL) {
		grid.setFocusColumn(grid.getColumn(focusCell.getColumnIndex()));
		grid.setFocusItem((GridItem) focusCell.getItem());
		
		if( selectionFollowsEditor ) {
			grid.setCellSelection(new Point(focusCell.getColumnIndex(),grid.indexOf((GridItem)focusCell.getItem())));
		}
	}
			
	grid.showColumn(grid.getColumn(focusCell.getColumnIndex()));
	grid.showItem((GridItem) focusCell.getItem()); 
}
 
Example #7
Source File: GridTableViewer.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void editElement(Object element, int column) {
	try {
		getControl().setRedraw(false);
		Widget item = findItem(element);
		if (item != null) {
			ViewerRow row = getViewerRowFromItem(item);
			if (row != null) {
				ViewerCell cell = row.getCell(column);
				if (cell != null) {
					triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(
							cell));
				}
			}
		}
	} finally {
		getControl().setRedraw(true);
	}
	// }
}
 
Example #8
Source File: GridViewerEditor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected void updateFocusCell(ViewerCell focusCell, ColumnViewerEditorActivationEvent event) {
	Grid grid = ((Grid)getViewer().getControl());

	if (event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC
			|| event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL) {
		grid.setFocusColumn(grid.getColumn(focusCell.getColumnIndex()));
		grid.setFocusItem((GridItem) focusCell.getItem());
		
		if( selectionFollowsEditor ) {
			grid.setCellSelection(new Point(focusCell.getColumnIndex(),grid.indexOf((GridItem)focusCell.getItem())));
		}
	}
			
	grid.showColumn(grid.getColumn(focusCell.getColumnIndex()));
	grid.showItem((GridItem) focusCell.getItem()); 
}
 
Example #9
Source File: GridViewerEditor.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected void updateFocusCell(ViewerCell focusCell, ColumnViewerEditorActivationEvent event) {
	if (event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC
			|| event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL) {
		Grid grid = ((Grid)getViewer().getControl());
		grid.deselectAllCells();
		grid.setFocusColumn(grid.getColumn(focusCell.getColumnIndex()));
		grid.setFocusItem((GridItem) focusCell.getItem());
		grid.setCellSelection(new Point(focusCell.getColumnIndex(),grid.indexOf((GridItem) focusCell.getItem())));
	}
}
 
Example #10
Source File: GridViewerShortTextPerformance.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public GridViewerShortTextPerformance(Shell shell)
{
	final GridTableViewer v = new GridTableViewer(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
	v.setLabelProvider(new MyLabelProvider());
	v.setContentProvider(new MyContentProvider());
	v.getGrid().setCellSelectionEnabled(true);

	v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getGrid()), new TextCellEditor(v.getGrid()) });

	v.setColumnProperties(new String[] { "1", "2" });

	ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v)
	{

		@Override
		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);
		}
	};

	GridViewerEditor.create(v, actSupport,
			ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
					| ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);

	for (int i = 0; i < NUM_COLUMNS; i++)
	{
		createColumn(v, "Column " + i);
	}

	MyModel[] model = createModel();
	v.setInput(model);
	v.getGrid().setLinesVisible(true);
	v.getGrid().setHeaderVisible(true);
}
 
Example #11
Source File: CharriageColumnViewerEditorActivationStrategyTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_isEditorActivationEvent_returns_false_if_pressed_another_key() throws Exception {
    final Event e = new Event();
    e.widget = tree;
    final KeyEvent event = new KeyEvent(e);
    event.keyCode = SWT.ARROW_DOWN;
    final ColumnViewerEditorActivationEvent activationEvent = new ColumnViewerEditorActivationEvent(cell, event);
    activationEvent.eventType = ColumnViewerEditorActivationEvent.KEY_PRESSED;
    assertThat(contractInputColumnViewerEditorActivationStrategy.isEditorActivationEvent(activationEvent)).isFalse();
}
 
Example #12
Source File: CharriageColumnViewerEditorActivationStrategyTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_isEditorActivationEvent_returns_true_if_pressed_enter_on_a_cell() throws Exception {
    final Event e = new Event();
    e.widget = tree;
    final KeyEvent event = new KeyEvent(e);
    event.keyCode = SWT.CR;
    final ColumnViewerEditorActivationEvent activationEvent = new ColumnViewerEditorActivationEvent(cell, event);
    activationEvent.eventType = ColumnViewerEditorActivationEvent.KEY_PRESSED;
    assertThat(contractInputColumnViewerEditorActivationStrategy.isEditorActivationEvent(activationEvent)).isTrue();
}
 
Example #13
Source File: CharriageColumnViewerEditorActivationStrategy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected boolean enterKeyPressed(final ColumnViewerEditorActivationEvent event) {
    final EventObject sourceEvent = event.sourceEvent;
    //event must not be cancelled
    if (sourceEvent instanceof KeyEvent && ((KeyEvent) sourceEvent).doit) {
        return event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR;
    }
    return false;
}
 
Example #14
Source File: LabResultEditingSupport.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
protected void setUpCellEditor(ColumnViewer viewer){
	// set up validation of the cell editors
	textCellEditor = new TextCellEditor((Composite) viewer.getControl());
	
	textCellEditor.addListener(new ICellEditorListener() {
		@Override
		public void editorValueChanged(boolean oldValidState, boolean newValidState){
			if (newValidState) {
				textCellEditor.getControl()
					.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
			} else {
				textCellEditor.getControl()
					.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
			}
		}
		
		@Override
		public void cancelEditor(){
			textCellEditor.getControl()
				.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
		}
		
		@Override
		public void applyEditorValue(){
			textCellEditor.getControl()
				.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
		}
	});
	
	focusCell =
		new TreeViewerFocusCellManager((TreeViewer) viewer, new FocusCellHighlighter(viewer) {
		
		});
		
	ColumnViewerEditorActivationStrategy actSupport =
		new ColumnViewerEditorActivationStrategy(viewer) {
			@Override
			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.KEY_PRESSED
						&& event.keyCode == SWT.KEYPAD_CR)
					|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
			}
		};
	
	TreeViewerEditor.create((TreeViewer) viewer, focusCell, actSupport,
		ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
}
 
Example #15
Source File: LabOrderEditingSupport.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
protected void setUpCellEditor(ColumnViewer viewer){
	// set up validation of the cell editors
	textCellEditor = new TextCellEditor((Composite) viewer.getControl());

	textCellEditor.addListener(new ICellEditorListener() {
		@Override
		public void editorValueChanged(boolean oldValidState, boolean newValidState){
			if (newValidState) {
				textCellEditor.getControl().setBackground(
					Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
			} else {
				textCellEditor.getControl().setBackground(
					Display.getCurrent().getSystemColor(SWT.COLOR_RED));
			}
		}
		
		@Override
		public void cancelEditor(){
			textCellEditor.getControl().setBackground(
				Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
		}
		
		@Override
		public void applyEditorValue(){
			textCellEditor.getControl().setBackground(
				Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
		}
	});
	
	focusCell =
		new TableViewerFocusCellManager((TableViewer) viewer, new FocusCellHighlighter(viewer) {
		
	});
	
	ColumnViewerEditorActivationStrategy actSupport =
		new ColumnViewerEditorActivationStrategy(viewer) {
			@Override
			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.KEY_PRESSED && event.keyCode == SWT.KEYPAD_CR)
					|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
			}
		};
	
	TableViewerEditor.create((TableViewer) viewer, focusCell, actSupport,
		ColumnViewerEditor.TABBING_VERTICAL
			| ColumnViewerEditor.KEYBOARD_ACTIVATION);
}
 
Example #16
Source File: CharriageColumnViewerEditorActivationStrategy.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected boolean isEditorActivationEvent(final ColumnViewerEditorActivationEvent event) {
    //Activate cell editor on Enter
    return super.isEditorActivationEvent(event)
            || enterKeyPressed(event);
}
 
Example #17
Source File: GenerericTableViewer.java    From offspring with MIT License 4 votes vote down vote up
@Override
public void setGenericTable(IGenericTable table) {
  this.table = table;

  setUseHashlookup(true);
  setContentProvider(table.getContentProvider());
  if (!(table.getContentProvider() instanceof IPageableStructeredContentProvider)) {
    this.comparator = new GenericComparator(table);
    setComparator(comparator);
  }

  ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(
      this) {

    @Override
    protected boolean isEditorActivationEvent(
        ColumnViewerEditorActivationEvent event) {
      return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
          || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
          || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
    }
  };

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

  createColumns();
  // try {
  // getTable().setRedraw(false);
  // calculateSizes();
  // }
  // finally {
  // getTable().setRedraw(true);
  // }

  // setInput(null);
  getTable().setHeaderVisible(true);
  getTable().setLinesVisible(true);
  getTable().layout();

  for (final IGenericTableColumn c : table.getColumns()) {
    if (c.getCellActivateHandler() != null) {
      getTable().addMouseMoveListener(mouseMoveListener);
      getTable().addMouseListener(mouseListener);
      break;
    }
  }
}
 
Example #18
Source File: GenerericTreeViewer.java    From offspring with MIT License 4 votes vote down vote up
@Override
public void setGenericTable(IGenericTable table) {
  this.table = table;

  setUseHashlookup(true);
  setContentProvider(table.getContentProvider());
  // if (!(table.getContentProvider() instanceof
  // IPageableStructeredContentProvider)) {
  // this.comparator = new GenericComparator(table);
  // setComparator(comparator);
  // }

  ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(
      this) {

    @Override
    protected boolean isEditorActivationEvent(
        ColumnViewerEditorActivationEvent event) {
      return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
          || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
          || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
    }
  };

  TreeViewerEditor.create(this, actSupport,
      ColumnViewerEditor.TABBING_HORIZONTAL
          | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
          | ColumnViewerEditor.TABBING_VERTICAL
          | ColumnViewerEditor.KEYBOARD_ACTIVATION);

  createColumns();

  // setInput(null);
  // getTree().setHeaderVisible(true);
  getTree().setLinesVisible(true);
  getTree().layout();

  for (final IGenericTableColumn c : table.getColumns()) {
    if (c.getCellActivateHandler() != null) {
      getTree().addMouseMoveListener(mouseMoveListener);
      getTree().addMouseListener(mouseListener);
      break;
    }
  }
}
 
Example #19
Source File: TaxonomyCheckboxListView.java    From slr-toolkit with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This is a callback that will allow us to create the viewer and initialize
 * it.
 */
@Override
public void createPartControl(Composite parent) {
	Optional<Model> m = ModelRegistryPlugin.getModelRegistry().getActiveTaxonomy();
	contentProvider = new TermContentProvider(viewer);
	viewer = new ContainerCheckedTreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
	viewer.setContentProvider(contentProvider);
	DecoratingLabelProvider p = new DecoratingLabelProvider(new DefaultEObjectLabelProvider(), new TaxonomyLabelDecorator());
	viewer.setLabelProvider(p);
	viewer.addCheckStateListener(this);
	viewer.setSorter(null);

	cellEditor = new MyTextCellEditor(viewer.getTree());

	TreeViewerEditor.create(
			viewer,
			new ColumnViewerEditorActivationStrategy(viewer){
				protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
					return event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION ||
							(event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.F2);
				}
			},
			TreeViewerEditor.DEFAULT
	);
	enableEditing();

	if(m.isPresent()){
		viewer.setInput(m.get());
	}
	viewer.expandAll();

	//Create right-click menu
       MenuManager menuManager = new MenuManager();
       Menu menu = menuManager.createContextMenu(viewer.getTree());
       viewer.getTree().setMenu(menu);
       getSite().registerContextMenu(menuManager, viewer);
	getSite().setSelectionProvider(viewer);
	// Create the help context id for the viewer's control
	PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "de.tudresden.slr.model.taxonomy.ui.viewer");
	getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
}