use of org.eclipse.swt.events.DisposeEvent in project tdi-studio-se by Talend.
the class DataMapTableView method addManualTableResizeListeners.
/**
* DOC amaumont Comment method "addManualTableResizeListeners".
*
* @param uiManager
*/
private void addManualTableResizeListeners(final UIManager uiManager) {
this.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (currentCursor != null) {
currentCursor.dispose();
}
}
});
Listener tableResizerListener = new Listener() {
@Override
public void handleEvent(Event event) {
MousePositionAnalyser mpa = new MousePositionAnalyser(DataMapTableView.this);
Point eventPoint = new Point(event.x, event.y);
boolean leftMouseButton = (event.stateMask & SWT.BUTTON1) != 0 || event.button == 1;
switch(event.type) {
case SWT.MouseMove:
if (resizeHelper.isDragging()) {
Point newPoint = convertToParentOrigin(DataMapTableView.this, eventPoint);
Point dragPoint = resizeHelper.getLastDragPoint();
Point diff = new Point(newPoint.x - dragPoint.x, newPoint.y - dragPoint.y);
if (mpa.isOnLeftBorder(eventPoint)) {
diff.x *= -1;
}
Rectangle rect = DataMapTableView.this.getClientArea();
rect.width += 2 * DataMapTableView.this.getBorderWidth();
rect.height += 2 * DataMapTableView.this.getBorderWidth();
RESIZE_MODE currentMode = resizeHelper.getCurrentMode();
int newWidth = (currentMode == RESIZE_MODE.HORIZONTAL || currentMode == RESIZE_MODE.BOTH) ? rect.width + diff.x * 2 : rect.width;
int newHeight = (currentMode == RESIZE_MODE.VERTICAL || currentMode == RESIZE_MODE.BOTH) ? rect.height + diff.y : rect.height;
if (newHeight < MINIMUM_HEIGHT + OFFSET_HEIGHT_TRIGGER && diff.y < 0) {
changeMinimizeState(true);
newHeight = MINIMUM_HEIGHT;
} else if (newHeight > MINIMUM_HEIGHT + OFFSET_HEIGHT_TRIGGER && diff.y > 0) {
changeMinimizeState(false);
}
changeSize(new Point(newWidth, newHeight), false, true);
resizeHelper.setLastDragPoint(newPoint);
} else if (!resizeHelper.isDragging()) {
Cursor cursor = null;
if (mpa.isOnLeftBottomCorner(eventPoint)) {
// cursor = new Cursor(dataMapTableView.getDisplay(), org.eclipse.swt.SWT.CURSOR_SIZESW);
// resizeHelper.setCurrentMode(RESIZE_MODE.BOTH);
} else if (mpa.isOnRightBottomCorner(eventPoint)) {
// cursor = new Cursor(dataMapTableView.getDisplay(), org.eclipse.swt.SWT.CURSOR_SIZESE);
// resizeHelper.setCurrentMode(RESIZE_MODE.BOTH);
} else if (mpa.isOnLeftBorder(eventPoint)) {
// cursor = new Cursor(dataMapTableView.getDisplay(), org.eclipse.swt.SWT.CURSOR_SIZEE);
// resizeHelper.setCurrentMode(RESIZE_MODE.HORIZONTAL);
} else if (mpa.isOnRightBorder(eventPoint)) {
// cursor = new Cursor(dataMapTableView.getDisplay(), org.eclipse.swt.SWT.CURSOR_SIZEW);
// resizeHelper.setCurrentMode(RESIZE_MODE.HORIZONTAL);
} else if (mpa.isOnBottomBorder(eventPoint)) {
cursor = new Cursor(DataMapTableView.this.getDisplay(), org.eclipse.swt.SWT.CURSOR_SIZES);
resizeHelper.setCurrentMode(RESIZE_MODE.VERTICAL);
}
if (cursor != null) {
DataMapTableView.this.setCursor(cursor);
} else {
setDefaultCursor();
resizeHelper.setCurrentMode(RESIZE_MODE.NONE);
}
}
break;
case SWT.MouseDown:
if (leftMouseButton) {
if (mpa.isOnLeftBorder(eventPoint) || mpa.isOnRightBorder(eventPoint) || mpa.isOnBottomBorder(eventPoint)) {
resizeHelper.startDrag(convertToParentOrigin(DataMapTableView.this, new Point(event.x, event.y)));
} else {
setDefaultCursor();
}
parentLayout = DataMapTableView.this.getParent().getLayout();
DataMapTableView.this.getParent().setLayout(null);
}
break;
case SWT.MouseUp:
if (leftMouseButton) {
resizeHelper.stopDrag();
// gridData = (GridData) dataMapTableView.getLayoutData();
// gridData.exclude = false;
DataMapTableView.this.getParent().setLayout(parentLayout);
DataMapTableView.this.getParent().layout();
uiManager.resizeTablesZoneViewAtComputedSize(getZone());
uiManager.refreshBackground(true, false);
}
break;
case SWT.MouseExit:
setDefaultCursor();
break;
default:
}
}
};
this.addListener(SWT.MouseMove, tableResizerListener);
this.addListener(SWT.MouseDown, tableResizerListener);
this.addListener(SWT.MouseUp, tableResizerListener);
}
use of org.eclipse.swt.events.DisposeEvent in project tdi-studio-se by Talend.
the class TalendFlyoutPaletteComposite method createActionMenu.
private Menu createActionMenu(Control parent) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
final MenuManager manager = new MenuManager();
MenuManager mgr = new MenuManager(PaletteMessages.DOCK_LABEL);
changeDockActionClass.getDeclaredConstructors();
// reflect the constructor of ChangeDockAction
Constructor changeDockActionConstructor = changeDockActionClass.getDeclaredConstructor(FlyoutPaletteComposite.class, String.class, int.class);
changeDockActionConstructor.setAccessible(true);
// instance of ChangeDockAction for left
Object changeDockActionInstance = changeDockActionConstructor.newInstance(this, PaletteMessages.LEFT_LABEL, PositionConstants.WEST);
if (changeDockActionInstance instanceof IAction) {
mgr.add((IAction) changeDockActionInstance);
}
// instance of ChangeDockAction for right
changeDockActionInstance = changeDockActionConstructor.newInstance(this, PaletteMessages.RIGHT_LABEL, PositionConstants.EAST);
if (changeDockActionInstance instanceof IAction) {
mgr.add((IAction) changeDockActionInstance);
}
// instance of ResizeAction
Constructor resizeActionConstructor = resizeActionClass.getDeclaredConstructor(FlyoutPaletteComposite.class);
resizeActionConstructor.setAccessible(true);
Object resizeActionInstance = resizeActionConstructor.newInstance(this);
if (resizeActionInstance instanceof IAction) {
mgr.add((IAction) resizeActionInstance);
}
manager.add(mgr);
mgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager menuMgr) {
IContributionItem[] items = menuMgr.getItems();
for (IContributionItem item : items) {
((ActionContributionItem) item).update();
}
}
});
//
// ShowStandardAction showStandardAction = ShowStandardAction.getInstance();
// ShowFavoriteAction showFavoriteAction = ShowFavoriteAction.getInstance();
// manager.add(showStandardAction);
// manager.add(showFavoriteAction);
// if (ShowFavoriteAction.state) {
// showStandardAction.doSetEnable();
// }
OpenPaletteFilterAction openPaletteFilterAction = OpenPaletteFilterAction.getInstance();
manager.add(openPaletteFilterAction);
manager.add(mgr);
addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
manager.dispose();
}
});
return manager.createContextMenu(this);
}
use of org.eclipse.swt.events.DisposeEvent in project cubrid-manager by CUBRID.
the class BLOBCellPopupDialog method constrainShellSize.
/**
* Constrain the shell size
*/
protected void constrainShellSize() {
super.constrainShellSize();
getShell().setSize(720, 540);
getShell().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
disposeImageCanvas();
}
});
if (isEditable) {
getShell().setText(Messages.titleEditData);
this.setMessage(Messages.msgEditData);
} else {
getShell().setText(Messages.titleViewData);
this.setMessage(Messages.msgViewData);
}
}
use of org.eclipse.swt.events.DisposeEvent in project cubrid-manager by CUBRID.
the class BLOBCellPopupDialog method loadProgramMenu.
/**
*
* Load the program menus
*
*/
private void loadProgramMenu() {
if (programMenu != null) {
programMenu.dispose();
}
programMenu = new Menu(getShell(), SWT.POP_UP);
String fileType = getFileType();
// Load the default application
if (fileType != null && fileType.trim().length() > 0) {
final Program program = Program.findProgram(fileType);
if (program != null && program.getName() != null && program.getName().trim().length() > 0) {
programMenuItem = new MenuItem(programMenu, SWT.NONE);
programMenuItem.setText(program.getName());
ImageData imageData = program.getImageData();
if (imageData != null) {
final Image image = new Image(getShell().getDisplay(), imageData);
programMenuItem.setImage(image);
programMenu.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
image.dispose();
}
});
}
programMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
openByExternalProgram(program);
}
});
new MenuItem(programMenu, SWT.SEPARATOR);
}
}
// Load the other applications
Program[] programs = Program.getPrograms();
if (programs != null) {
for (final Program program : programs) {
String name = program.getName();
if (name == null || name.trim().length() == 0) {
continue;
}
if (programMenuItem != null && programMenuItem.getText().equals(name.trim())) {
continue;
}
final MenuItem selectProgramMenuItem = new MenuItem(programMenu, SWT.NONE);
selectProgramMenuItem.setText(name);
ImageData imageData = program.getImageData();
if (imageData != null) {
final Image image = new Image(getShell().getDisplay(), imageData);
selectProgramMenuItem.setImage(image);
selectProgramMenuItem.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
image.dispose();
}
});
}
selectProgramMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
openByExternalProgram(program);
}
});
}
}
Rectangle rect = openByExternalBtn.getBounds();
Point pt = new Point(rect.x, rect.y + rect.height);
pt = openByExternalBtn.getParent().toDisplay(pt);
programMenu.setLocation(pt);
programMenu.setVisible(true);
}
use of org.eclipse.swt.events.DisposeEvent in project dbeaver by serge-rider.
the class MetaDataPanel method createContents.
@Override
public Control createContents(final IResultSetPresentation presentation, Composite parent) {
this.presentation = presentation;
this.colorDisabled = presentation.getControl().getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
this.attributeList = new MetaDataTable(parent);
this.attributeList.setFitWidth(false);
this.attributeList.getItemsViewer().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
DBDAttributeBinding attr = getSelectedAttribute();
if (attr != null && !updateSelection) {
if (isAttributeVisible(attr)) {
updateSelection = true;
try {
presentation.setCurrentAttribute(attr);
} finally {
updateSelection = false;
}
}
}
}
});
if (this.presentation instanceof ISelectionProvider) {
final ISelectionChangedListener listener = new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (!updateSelection && MetaDataPanel.this.presentation.getController().getVisiblePanel() == MetaDataPanel.this) {
DBDAttributeBinding attr = presentation.getCurrentAttribute();
if (attr != null && attr != getSelectedAttribute()) {
updateSelection = true;
try {
attributeList.getItemsViewer().setSelection(new StructuredSelection(attr));
} finally {
updateSelection = false;
}
}
}
}
};
((ISelectionProvider) this.presentation).addSelectionChangedListener(listener);
attributeList.getControl().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
((ISelectionProvider) presentation).removeSelectionChangedListener(listener);
}
});
}
return this.attributeList;
}
Aggregations