use of org.eclipse.swt.events.SelectionEvent in project translationstudio8 by heartsome.
the class Grid method onMouseDown.
/**
* Mouse down event handler.
*
* @param e event
*/
private void onMouseDown(MouseEvent e) {
// forceFocus()
if ((getStyle() & SWT.NO_FOCUS) != SWT.NO_FOCUS) {
forceFocus();
}
hideToolTip();
//if populated will be fired at end of method.
Event selectionEvent = null;
cellSelectedOnLastMouseDown = false;
cellRowSelectedOnLastMouseDown = false;
cellColumnSelectedOnLastMouseDown = false;
if (hoveringOnColumnResizer) {
if (e.button == 1) {
resizingColumn = true;
resizingStartX = e.x;
resizingColumnStartWidth = columnBeingResized.getWidth();
}
return;
}
if (rowsResizeable && hoveringOnRowResizer) {
if (e.button == 1) {
resizingRow = true;
resizingStartY = e.y;
resizingRowStartHeight = rowBeingResized.getHeight();
}
return;
}
if (e.button == 1 && handleColumnHeaderPush(e.x, e.y)) {
return;
}
if (e.button == 1 && handleColumnGroupHeaderClick(e.x, e.y)) {
return;
}
if (e.button == 1 && handleColumnFooterPush(e.x, e.y)) {
return;
}
GridItem item = getItem(new Point(e.x, e.y));
if (e.button == 1 && item != null && handleCellClick(item, e.x, e.y)) {
return;
}
if (isListening(SWT.DragDetect)) {
if ((cellSelectionEnabled && hoveringOnSelectionDragArea) || (!cellSelectionEnabled && item != null && selectedItems.contains(item))) {
if (dragDetect(e)) {
return;
}
}
}
if (item != null) {
if (cellSelectionEnabled) {
GridColumn col = getColumn(new Point(e.x, e.y));
boolean isSelectedCell = false;
if (col != null)
isSelectedCell = selectedCells.contains(new Point(indexOf(col), indexOf(item)));
if (e.button == 1 || (e.button == 3 && col != null && !isSelectedCell)) {
if (col != null) {
selectionEvent = updateCellSelection(new Point(indexOf(col), indexOf(item)), e.stateMask, false, true);
cellSelectedOnLastMouseDown = (getCellSelectionCount() > 0);
if (e.stateMask != SWT.MOD2) {
focusColumn = col;
focusItem = item;
}
//showColumn(col);
showItem(item);
redraw();
} else if (rowHeaderVisible) {
if (e.x <= rowHeaderWidth) {
boolean shift = ((e.stateMask & SWT.MOD2) != 0);
boolean ctrl = false;
if (!shift) {
ctrl = ((e.stateMask & SWT.MOD1) != 0);
}
Vector cells = new Vector();
if (shift) {
getCells(item, focusItem, cells);
} else {
getCells(item, cells);
}
int newStateMask = SWT.NONE;
if (ctrl)
newStateMask = SWT.MOD1;
selectionEvent = updateCellSelection(cells, newStateMask, shift, ctrl);
cellRowSelectedOnLastMouseDown = (getCellSelectionCount() > 0);
if (!shift) {
//set focus back to the first visible column
focusColumn = getColumn(new Point(rowHeaderWidth + 1, e.y));
focusItem = item;
}
showItem(item);
redraw();
}
}
intendedFocusColumn = focusColumn;
}
} else {
if (e.button == 2 || e.button > 3) {
return;
}
if (e.button == 3 && selectionType == SWT.MULTI) {
if ((e.stateMask & SWT.MOD2) == SWT.MOD2) {
return;
}
if ((e.stateMask & SWT.MOD1) == SWT.MOD1) {
return;
}
if (selectedItems.contains(item)) {
return;
}
}
selectionEvent = updateSelection(item, e.stateMask);
focusItem = item;
showItem(item);
redraw();
}
} else if (e.button == 1 && rowHeaderVisible && e.x <= rowHeaderWidth && e.y < headerHeight) {
// Nothing to select
if (items.size() == 0) {
return;
}
if (cellSelectionEnabled) {
//click on the top left corner means select everything
selectionEvent = selectAllCellsInternal();
focusColumn = getColumn(new Point(rowHeaderWidth + 1, 1));
} else {
//click on the top left corner means select everything
selectionEvent = selectAllRowsInternal();
}
focusItem = getItem(getTopIndex());
} else if (cellSelectionEnabled && e.button == 1 && columnHeadersVisible && e.y <= headerHeight) {
//column cell selection
GridColumn col = getColumn(new Point(e.x, e.y));
if (col == null)
return;
if (getItemCount() == 0)
return;
Vector cells = new Vector();
GridColumnGroup group = col.getColumnGroup();
if (group != null && e.y < groupHeaderHeight) {
getCells(group, cells);
} else {
getCells(col, cells);
}
selectionEvent = updateCellSelection(cells, e.stateMask, false, true);
cellColumnSelectedOnLastMouseDown = (getCellSelectionCount() > 0);
GridItem newFocusItem = getItem(0);
while (newFocusItem != null && getSpanningColumn(newFocusItem, col) != null) {
newFocusItem = getNextVisibleItem(newFocusItem);
}
if (newFocusItem != null) {
focusColumn = col;
focusItem = newFocusItem;
}
showColumn(col);
redraw();
}
if (selectionEvent != null) {
selectionEvent.stateMask = e.stateMask;
selectionEvent.button = e.button;
selectionEvent.item = item;
selectionEvent.x = e.x;
selectionEvent.y = e.y;
notifyListeners(SWT.Selection, selectionEvent);
if (!cellSelectionEnabled) {
if (isListening(SWT.DragDetect)) {
dragDetect(e);
}
}
}
}
use of org.eclipse.swt.events.SelectionEvent in project translationstudio8 by heartsome.
the class Grid method updateSelection.
/**
* Adds/removes items from the selected items list based on the
* selection/deselection of the given item.
*
* @param item item being selected/unselected
* @param stateMask key state during selection
*
* @return selection event that needs to be fired or null
*/
private Event updateSelection(GridItem item, int stateMask) {
if (!selectionEnabled) {
return null;
}
Event selectionEvent = null;
if (selectionType == SWT.SINGLE) {
if (selectedItems.contains(item)) {
// Deselect when pressing CTRL
if ((stateMask & SWT.MOD1) == SWT.MOD1) {
selectedItems.clear();
}
} else {
selectedItems.clear();
selectedItems.add(item);
}
Rectangle clientArea = getClientArea();
redraw(clientArea.x, clientArea.y, clientArea.width, clientArea.height, false);
selectionEvent = new Event();
selectionEvent.item = item;
} else if (selectionType == SWT.MULTI) {
boolean shift = false;
boolean ctrl = false;
if ((stateMask & SWT.MOD2) == SWT.MOD2) {
shift = true;
}
if ((stateMask & SWT.MOD1) == SWT.MOD1) {
ctrl = true;
}
if (!shift && !ctrl) {
if (selectedItems.size() == 1 && selectedItems.contains(item))
return null;
selectedItems.clear();
selectedItems.add(item);
Rectangle clientArea = getClientArea();
redraw(clientArea.x, clientArea.y, clientArea.width, clientArea.height, false);
shiftSelectionAnchorItem = null;
selectionEvent = new Event();
selectionEvent.item = item;
} else if (shift) {
if (shiftSelectionAnchorItem == null) {
shiftSelectionAnchorItem = focusItem;
}
// if (shiftSelectionAnchorItem == item)
// {
// return;
// }
boolean maintainAnchorSelection = false;
if (!ctrl) {
if (selectedItems.contains(shiftSelectionAnchorItem)) {
maintainAnchorSelection = true;
}
selectedItems.clear();
}
int anchorIndex = items.indexOf(shiftSelectionAnchorItem);
int itemIndex = items.indexOf(item);
int min = 0;
int max = 0;
if (anchorIndex < itemIndex) {
if (maintainAnchorSelection) {
min = anchorIndex;
} else {
min = anchorIndex + 1;
}
max = itemIndex;
} else {
if (maintainAnchorSelection) {
max = anchorIndex;
} else {
max = anchorIndex - 1;
}
min = itemIndex;
}
for (int i = min; i <= max; i++) {
if (!selectedItems.contains(items.get(i)) && ((GridItem) items.get(i)).isVisible()) {
selectedItems.add((GridItem) items.get(i));
}
}
Rectangle clientArea = getClientArea();
redraw(clientArea.x, clientArea.y, clientArea.width, clientArea.height, false);
selectionEvent = new Event();
} else if (ctrl) {
if (selectedItems.contains(item)) {
selectedItems.remove(item);
} else {
selectedItems.add(item);
}
Rectangle clientArea = getClientArea();
redraw(clientArea.x, clientArea.y, clientArea.width, clientArea.height, false);
shiftSelectionAnchorItem = null;
selectionEvent = new Event();
selectionEvent.item = item;
}
}
Rectangle clientArea = getClientArea();
redraw(clientArea.x, clientArea.y, clientArea.width, clientArea.height, false);
return selectionEvent;
}
use of org.eclipse.swt.events.SelectionEvent in project translationstudio8 by heartsome.
the class BrowserViewPart method createSearchArea.
private Composite createSearchArea(Composite parent) {
GridLayout gridLayout = new GridLayout(3, false);
parent.setLayout(gridLayout);
GridData gd_seachArea = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
parent.setLayoutData(gd_seachArea);
keyWordForSearch = new Text(parent, SWT.SEARCH);
GridData gd_keyWordForSearch = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
gd_keyWordForSearch.heightHint = 20;
keyWordForSearch.setLayoutData(gd_keyWordForSearch);
keyWordForSearch.setText("");
font = keyWordForSearch.getFont();
FontData fontData = font.getFontData()[0];
fontData.setStyle(fontData.getStyle());
fontData.setHeight(12);
font = new Font(Display.getDefault(), fontData);
keyWordForSearch.setFont(font);
keyWordForSearch.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
if (e.keyCode == SWT.CR || e.keyCode == SWT.LF) {
refreshKeyWordSearch(true);
}
}
});
Button searchBtn = new Button(parent, SWT.NONE);
searchBtn.setText(Messages.getString("Websearch.browserViewPart.searchBtnLbl"));
searchBtn.setLayoutData(new GridData(GridData.FILL_VERTICAL));
searchBtn.addSelectionListener(new SelectionAdapter() {
/**
* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
refreshKeyWordSearch(true);
}
});
Button settingBtn = new Button(parent, SWT.NONE);
settingBtn.setText(Messages.getString("Websearch.browserViewPart.settingBtnLbl"));
settingBtn.setLayoutData(new GridData(GridData.FILL_VERTICAL));
settingBtn.addSelectionListener(new SelectionAdapter() {
/**
* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
PreferenceUtil.openPreferenceDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), WebSearchPreferencePage.ID);
}
});
return parent;
}
use of org.eclipse.swt.events.SelectionEvent in project translationstudio8 by heartsome.
the class WebSearchPreferencePage method installListeners.
private void installListeners() {
checkboxTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateState();
}
});
upItemBtn.addSelectionListener(new SelectionAdapter() {
/**
* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
upSelectItem();
}
});
downItemBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
downSelectItem();
}
});
deleteItemBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
deleteSelectItem();
}
});
addItemBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
addItem();
}
});
editItemBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
editItem();
}
});
importItemsBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
importConfig();
}
});
exportItemsBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
exportConfig();
}
});
}
use of org.eclipse.swt.events.SelectionEvent in project translationstudio8 by heartsome.
the class WorkingSetRootModeActionGroup method addActions.
/**
* Adds the actions to the given menu manager.
*/
protected void addActions(IMenuManager viewMenu) {
if (actions == null)
actions = createActions();
viewMenu.add(new Separator());
items = new MenuItem[actions.length];
for (int i = 0; i < actions.length; i++) {
final int j = i;
viewMenu.add(new ContributionItem() {
public void fill(Menu menu, int index) {
int style = SWT.CHECK;
if ((actions[j].getStyle() & IAction.AS_RADIO_BUTTON) != 0)
style = SWT.RADIO;
final MenuItem mi = new MenuItem(menu, style, index);
items[j] = mi;
mi.setText(actions[j].getText());
mi.setSelection(currentSelection == j);
mi.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (currentSelection == j) {
items[currentSelection].setSelection(true);
return;
}
actions[j].run();
// Update checked state
items[currentSelection].setSelection(false);
currentSelection = j;
items[currentSelection].setSelection(true);
}
});
}
public boolean isDynamic() {
return false;
}
});
}
}
Aggregations