use of org.eclipse.jface.viewers.ISelection in project dbeaver by serge-rider.
the class NavigatorHandlerRefresh method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
//final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final IWorkbenchPart workbenchPart = HandlerUtil.getActivePart(event);
INavigatorModelView navigatorView;
if (workbenchPart instanceof INavigatorModelView) {
navigatorView = (INavigatorModelView) workbenchPart;
} else {
navigatorView = workbenchPart.getAdapter(INavigatorModelView.class);
}
if (navigatorView == null) {
// Try to refresh as refreshable part
if (workbenchPart instanceof IRefreshablePart) {
((IRefreshablePart) workbenchPart).refreshPart(this, true);
}
return null;
}
final List<DBNNode> refreshObjects = new ArrayList<>();
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode rootNode = navigatorView.getRootNode();
if (rootNode == null) {
if (workbenchPart instanceof IEditorPart) {
if (((IEditorPart) workbenchPart).getEditorInput() instanceof IDatabaseEditorInput) {
rootNode = ((IDatabaseEditorInput) ((IEditorPart) workbenchPart).getEditorInput()).getNavigatorNode();
}
}
}
if (rootNode != null && rootNode.getParentNode() instanceof DBNDatabaseNode) {
refreshObjects.add(rootNode);
} else if (selection instanceof IStructuredSelection) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
Object object = iter.next();
if (object instanceof DBNNode) {
refreshObjects.add((DBNNode) object);
}
}
}
// Refresh objects
if (!refreshObjects.isEmpty()) {
refreshNavigator(refreshObjects);
}
return null;
}
use of org.eclipse.jface.viewers.ISelection in project dbeaver by serge-rider.
the class NavigatorHandlerCreateLink method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
Object element = structSelection.getFirstElement();
if (!(element instanceof DBNResource)) {
return null;
}
final IResource resource = ((DBNResource) element).getResource();
if (resource instanceof IFolder) {
final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
DirectoryDialog dialog = new DirectoryDialog(workbenchWindow.getShell(), SWT.NONE);
String folder = dialog.open();
if (folder != null) {
createLink(workbenchWindow, (IFolder) resource, folder);
}
}
}
return null;
}
use of org.eclipse.jface.viewers.ISelection in project dbeaver by serge-rider.
the class NavigatorHandlerFilterConfig method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode node = NavigatorUtils.getSelectedNode(selection);
if (node instanceof DBNDatabaseItem) {
node = node.getParentNode();
}
if (node instanceof DBNDatabaseFolder) {
configureFilters(HandlerUtil.getActiveShell(event), node);
}
return null;
}
use of org.eclipse.jface.viewers.ISelection in project dbeaver by serge-rider.
the class NavigatorHandlerObjectCreateCopy method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode curNode = NavigatorUtils.getSelectedNode(selection);
if (curNode != null) {
Clipboard clipboard = new Clipboard(Display.getDefault());
try {
@SuppressWarnings("unchecked") Collection<DBNNode> cbNodes = (Collection<DBNNode>) clipboard.getContents(TreeNodeTransfer.getInstance());
if (cbNodes != null) {
for (DBNNode nodeObject : cbNodes) {
if (nodeObject instanceof DBNDatabaseNode) {
createNewObject(HandlerUtil.getActiveWorkbenchWindow(event), curNode, ((DBNDatabaseNode) nodeObject));
} else if (nodeObject instanceof DBNResource && curNode instanceof DBNResource) {
pasteResource((DBNResource) nodeObject, (DBNResource) curNode);
}
}
} else if (curNode instanceof DBNResource) {
String[] files = (String[]) clipboard.getContents(FileTransfer.getInstance());
if (files != null) {
for (String fileName : files) {
final File file = new File(fileName);
if (file.exists()) {
pasteResource(file, (DBNResource) curNode);
}
}
} else {
UIUtils.showErrorDialog(HandlerUtil.getActiveShell(event), "Paste error", "Unsupported clipboard format. File or folder were expected.");
}
} else {
UIUtils.showErrorDialog(HandlerUtil.getActiveShell(event), "Paste error", "Clipboard contains data in unsupported format");
}
} finally {
clipboard.dispose();
}
}
return null;
}
use of org.eclipse.jface.viewers.ISelection in project dbeaver by serge-rider.
the class NavigatorHandlerObjectCreateNew method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode node = NavigatorUtils.getSelectedNode(selection);
if (node != null) {
createNewObject(HandlerUtil.getActiveWorkbenchWindow(event), node, null);
}
return null;
}
Aggregations