use of org.eclipse.jface.viewers.ISelection in project dbeaver by serge-rider.
the class AbstractCommentHandler method execute.
public final Object execute(ExecutionEvent event) throws ExecutionException {
BaseTextEditor textEditor = BaseTextEditor.getTextEditor(HandlerUtil.getActiveEditor(event));
if (textEditor != null) {
ICommentsSupport commentsSupport = textEditor.getCommentsSupport();
IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
if (document != null && commentsSupport != null) {
// get current text selection
ISelectionProvider provider = textEditor.getSelectionProvider();
if (provider != null) {
ISelection selection = provider.getSelection();
if (selection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection) selection;
if (!textSelection.isEmpty()) {
try {
processAction(textEditor.getSelectionProvider(), commentsSupport, document, textSelection);
} catch (BadLocationException e) {
log.warn(e);
}
}
}
}
}
}
return null;
}
use of org.eclipse.jface.viewers.ISelection in project dbeaver by serge-rider.
the class CompileHandler method getSelectedObjects.
private List<OracleSourceObject> getSelectedObjects(ExecutionEvent event) {
List<OracleSourceObject> objects = new ArrayList<>();
final ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
if (currentSelection instanceof IStructuredSelection && !currentSelection.isEmpty()) {
for (Iterator<?> iter = ((IStructuredSelection) currentSelection).iterator(); iter.hasNext(); ) {
final Object element = iter.next();
final OracleSourceObject sourceObject = RuntimeUtils.getObjectAdapter(element, OracleSourceObject.class);
if (sourceObject != null) {
objects.add(sourceObject);
}
}
}
if (objects.isEmpty()) {
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
final OracleSourceObject sourceObject = RuntimeUtils.getObjectAdapter(activePart, OracleSourceObject.class);
if (sourceObject != null) {
objects.add(sourceObject);
}
}
return objects;
}
use of org.eclipse.jface.viewers.ISelection in project translationstudio8 by heartsome.
the class TermDbManagerDialog method initTreePopMenu.
/**
* 初始化树右键菜单 ;
*/
private void initTreePopMenu() {
MenuManager menuManager = new MenuManager("");
menuManager.add(new Action(Messages.getString("dialog.TermDbManagerDialog.deleteAction")) {
@Override
public void run() {
ISelection selection = getTreeViewer().getSelection();
if (selection.isEmpty()) {
return;
}
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object obj = structuredSelection.getFirstElement();
if (obj instanceof DatabaseModelBean) {
List<DatabaseModelBean> currDbTypeServers = treeInputMap.get(currDbType);
configer.deleteServerById(((DatabaseModelBean) obj).getId());
int i = currDbTypeServers.indexOf(obj);
currDbTypeServers.remove(i);
getTreeViewer().refresh();
if (currDbTypeServers.size() != 0) {
if (i > currDbTypeServers.size() - 1) {
setLastSelectedServer(currDbTypeServers.get(i - 1).getId());
} else {
setLastSelectedServer(currDbTypeServers.get(i).getId());
}
initUI(false);
} else {
setLastSelectedServer(null);
initUI(true);
}
selectSaveItem();
}
}
});
Tree tree = treeViewer.getTree();
this.treePopMenu = menuManager.createContextMenu(tree);
}
use of org.eclipse.jface.viewers.ISelection in project translationstudio8 by heartsome.
the class TermDbManagerDialog method executeSelectDatabase.
/**
* 当使用该对话框作为数据库选择时 ;
*/
private void executeSelectDatabase() {
ISelection selection = getDbTableViewer().getSelection();
if (selection.isEmpty()) {
return;
}
hasSelected = new HashMap<DatabaseModelBean, String>();
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Iterator<?> it = structuredSelection.iterator();
while (it.hasNext()) {
DatabaseManagerDbListBean dbBean = (DatabaseManagerDbListBean) it.next();
DatabaseModelBean dbModelBean = new DatabaseModelBean();
currServer.copyToOtherIntance(dbModelBean);
dbModelBean.setDbName(dbBean.getDbName());
// Fix Bug #3290 导出TMX/TBX--导出内容异常 去掉语言前后的空格
hasSelected.put(dbModelBean, dbBean.getLangs().replace(" ", ""));
}
}
use of org.eclipse.jface.viewers.ISelection in project translationstudio8 by heartsome.
the class AbstractSelectProjectFilesHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
shell = HandlerUtil.getActiveShell(event);
isEditor = false;
// UNDO 如果焦点在其他视图上时,获取的文件错误。
ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
if (selection == null || !(selection instanceof StructuredSelection) || selection.isEmpty()) {
MessageDialog.openInformation(shell, Messages.getString("handlers.AbstractSelectProjectFilesHandler.msgTitle"), Messages.getString("handlers.AbstractSelectProjectFilesHandler.msg1"));
return null;
}
StructuredSelection structuredSelection = (StructuredSelection) selection;
IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
String partId = HandlerUtil.getActivePartIdChecked(event);
if (part instanceof IEditorPart) {
// 当前焦点在编辑器
IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
isEditor = true;
ArrayList<IFile> list = new ArrayList<IFile>();
//代替 Arrays.asList(iFile)
list.add(iFile);
return execute(event, list);
} else if ("net.heartsome.cat.common.ui.navigator.view".equals(partId)) {
// 当前焦点在导航视图
ArrayList<IFile> list = new ArrayList<IFile>();
ArrayList<IFile> wrongFiles = new ArrayList<IFile>();
String projectName = null;
@SuppressWarnings("unchecked") Iterator<IResource> iterator = structuredSelection.iterator();
while (iterator.hasNext()) {
IResource resource = iterator.next();
if (projectName == null) {
projectName = resource.getProject().getName();
} else {
if (!projectName.equals(resource.getProject().getName())) {
MessageDialog.openInformation(shell, Messages.getString("handlers.AbstractSelectProjectFilesHandler.msgTitle"), Messages.getString("handlers.AbstractSelectProjectFilesHandler.msg2"));
return null;
}
}
if (resource instanceof IFile) {
IFile file = (IFile) resource;
String fileExtension = file.getFileExtension();
if (getLegalFileExtensions() == null || getLegalFileExtensions().length == 0) {
// 未限制后缀名的情况
list.add(file);
} else {
// 限制了后缀名的情况
if (fileExtension == null) {
// 无后缀名的文件
fileExtension = "";
}
if (CommonFunction.containsIgnoreCase(getLegalFileExtensions(), fileExtension)) {
list.add(file);
} else {
wrongFiles.add(file);
}
}
} else if (resource instanceof IContainer) {
// IContainer 包含 IFolder、IPorject。
try {
ResourceUtils.getFiles((IContainer) resource, list, getLegalFileExtensions());
} catch (CoreException e) {
LOGGER.error(MessageFormat.format(Messages.getString("handlers.AbstractSelectProjectFilesHandler.msg3"), resource.getFullPath().toOSString()), e);
e.printStackTrace();
}
}
}
if (!wrongFiles.isEmpty()) {
String msg = Messages.getString("handlers.AbstractSelectProjectFilesHandler.msg4");
StringBuffer arg = new StringBuffer();
for (IFile iFile : wrongFiles) {
arg.append("\n").append(iFile.getFullPath().toOSString());
}
if (!MessageDialog.openConfirm(shell, Messages.getString("handlers.AbstractSelectProjectFilesHandler.msgTitle"), MessageFormat.format(msg.toString(), arg.toString()))) {
return null;
}
}
return execute(event, list);
}
return null;
}
Aggregations