use of org.jkiss.dbeaver.core.DBeaverCore in project dbeaver by serge-rider.
the class NavigatorHandlerProjectSelect method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final DBeaverCore core = DBeaverCore.getInstance();
final DBNProject projectNode = core.getNavigatorModel().getRoot().getProject(core.getProjectRegistry().getActiveProject());
if (projectNode != null) {
final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
try {
final ProjectNavigatorView projectsView = (ProjectNavigatorView) workbenchWindow.getActivePage().showView(ProjectNavigatorView.VIEW_ID);
if (projectsView != null) {
projectsView.showNode(projectNode);
}
} catch (PartInitException e) {
log.error(e);
}
}
return null;
}
use of org.jkiss.dbeaver.core.DBeaverCore in project dbeaver by serge-rider.
the class SelectDataSourceDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
getShell().setText(CoreMessages.dialog_select_datasource_title);
Composite group = (Composite) super.createDialogArea(parent);
GridData gd = new GridData(GridData.FILL_BOTH);
group.setLayoutData(gd);
DBeaverCore core = DBeaverCore.getInstance();
DBNNode rootNode = null;
if (project != null) {
DBNProject projectNode = core.getNavigatorModel().getRoot().getProject(project);
if (projectNode != null) {
rootNode = projectNode.getDatabases();
}
}
if (rootNode == null) {
rootNode = core.getNavigatorModel().getRoot();
}
DatabaseNavigatorTree dataSourceTree = new DatabaseNavigatorTree(group, rootNode, SWT.SINGLE | SWT.BORDER, false);
dataSourceTree.setLayoutData(new GridData(GridData.FILL_BOTH));
final Text descriptionText = new Text(group, SWT.READ_ONLY);
descriptionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
dataSourceTree.getViewer().addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return element instanceof DBNProject || element instanceof DBNProjectDatabases || element instanceof DBNLocalFolder || element instanceof DBNDataSource;
}
});
dataSourceTree.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection structSel = (IStructuredSelection) event.getSelection();
Object selNode = structSel.isEmpty() ? null : structSel.getFirstElement();
if (selNode instanceof DBNDataSource) {
dataSource = ((DBNDataSource) selNode).getObject();
getButton(IDialogConstants.OK_ID).setEnabled(true);
String description = dataSource.getDescription();
if (description == null) {
description = dataSource.getName();
}
descriptionText.setText(description);
} else {
dataSource = null;
getButton(IDialogConstants.OK_ID).setEnabled(false);
}
}
});
dataSourceTree.getViewer().addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
if (getButton(IDialogConstants.OK_ID).isEnabled()) {
okPressed();
}
}
});
return group;
}
use of org.jkiss.dbeaver.core.DBeaverCore in project dbeaver by serge-rider.
the class ProjectRegistry method loadProjects.
public void loadProjects(IProgressMonitor monitor) throws DBException {
final DBeaverCore core = DBeaverCore.getInstance();
String activeProjectName = DBeaverCore.getGlobalPreferenceStore().getString(PROP_PROJECT_ACTIVE);
List<IProject> projects = core.getLiveProjects();
monitor.beginTask("Open active project", projects.size());
try {
for (IProject project : projects) {
if (project.exists() && !project.isHidden()) {
if (project.getName().equals(activeProjectName)) {
activeProject = project;
break;
} else if (activeProject == null) {
// By default use first project
activeProject = project;
}
}
monitor.worked(1);
}
if (activeProject != null) {
try {
activeProject.open(monitor);
activeProject.refreshLocal(IFile.DEPTH_ONE, monitor);
setActiveProject(activeProject);
} catch (CoreException e) {
// Project seems to be corrupted
projects.remove(activeProject);
activeProject = null;
}
}
} finally {
monitor.done();
}
if (DBeaverCore.isStandalone() && CommonUtils.isEmpty(projects)) {
// Create initial project (only for standalone version)
monitor.beginTask("Create general project", 1);
try {
activeProject = createGeneralProject(monitor);
activeProject.open(monitor);
setActiveProject(activeProject);
} catch (CoreException e) {
throw new DBException("Can't create default project", e);
} finally {
monitor.done();
}
}
}
use of org.jkiss.dbeaver.core.DBeaverCore in project dbeaver by serge-rider.
the class ApplicationWorkbenchWindowAdvisor method dispose.
@Override
public void dispose() {
// Remove project listener
DBeaverCore core = DBeaverCore.getInstance();
if (core != null) {
ProjectRegistry projectRegistry = core.getProjectRegistry();
if (projectRegistry != null) {
projectRegistry.removeProjectListener(this);
}
}
super.dispose();
}
use of org.jkiss.dbeaver.core.DBeaverCore in project dbeaver by serge-rider.
the class SearchDataPage method createControl.
@Override
public void createControl(Composite parent) {
super.createControl(parent);
initializeDialogUnits(parent);
Composite searchGroup = new Composite(parent, SWT.NONE);
searchGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
searchGroup.setLayout(new GridLayout(3, false));
setControl(searchGroup);
UIUtils.createControlLabel(searchGroup, "String");
searchText = new Combo(searchGroup, SWT.DROP_DOWN);
searchText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
if (params.searchString != null) {
searchText.setText(params.searchString);
}
for (String history : searchHistory) {
searchText.add(history);
}
searchText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
params.searchString = searchText.getText();
updateEnablement();
}
});
Composite optionsGroup = new SashForm(searchGroup, SWT.NONE);
GridLayout layout = new GridLayout(2, true);
layout.marginHeight = 0;
layout.marginWidth = 0;
optionsGroup.setLayout(layout);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 3;
optionsGroup.setLayoutData(gd);
{
final DBeaverCore core = DBeaverCore.getInstance();
Group databasesGroup = UIUtils.createControlGroup(optionsGroup, "Databases", 1, GridData.FILL_BOTH, 0);
gd = new GridData(GridData.FILL_BOTH);
//gd.heightHint = 300;
databasesGroup.setLayoutData(gd);
final DBNProject projectNode = core.getNavigatorModel().getRoot().getProject(core.getProjectRegistry().getActiveProject());
DBNNode rootNode = projectNode == null ? core.getNavigatorModel().getRoot() : projectNode.getDatabases();
dataSourceTree = new DatabaseNavigatorTree(databasesGroup, rootNode, SWT.SINGLE | SWT.CHECK);
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
dataSourceTree.setLayoutData(gd);
final CheckboxTreeViewer viewer = (CheckboxTreeViewer) dataSourceTree.getViewer();
viewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof TreeLoadNode) {
return true;
}
if (element instanceof DBNNode) {
if (element instanceof DBNDatabaseFolder) {
DBNDatabaseFolder folder = (DBNDatabaseFolder) element;
Class<? extends DBSObject> folderItemsClass = folder.getChildrenClass();
return folderItemsClass != null && (DBSObjectContainer.class.isAssignableFrom(folderItemsClass) || DBSEntity.class.isAssignableFrom(folderItemsClass));
}
if (element instanceof DBNLocalFolder || element instanceof DBNProjectDatabases || element instanceof DBNDataSource) {
return true;
}
if (element instanceof DBSWrapper) {
DBSObject obj = ((DBSWrapper) element).getObject();
if (obj instanceof DBSObjectContainer)
return true;
if (obj instanceof DBSDataContainer && obj instanceof DBSEntity) {
if ((((DBSDataContainer) obj).getSupportedFeatures() & DBSDataContainer.DATA_SEARCH) != 0) {
return true;
}
}
}
}
return false;
}
});
checkboxTreeManager = new CheckboxTreeManager(viewer, new Class[] { DBSDataContainer.class });
viewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
updateEnablement();
}
});
}
{
//new Label(searchGroup, SWT.NONE);
Composite optionsGroup2 = UIUtils.createControlGroup(optionsGroup, "Settings", 2, GridData.FILL_HORIZONTAL, 0);
optionsGroup2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING));
if (params.maxResults <= 0) {
params.maxResults = 10;
}
final Spinner maxResultsSpinner = UIUtils.createLabelSpinner(optionsGroup2, "Sample rows", params.maxResults, 1, Integer.MAX_VALUE);
maxResultsSpinner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
maxResultsSpinner.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
params.maxResults = maxResultsSpinner.getSelection();
}
});
final Button caseCheckbox = UIUtils.createLabelCheckbox(optionsGroup2, CoreMessages.dialog_search_objects_case_sensitive, params.caseSensitive);
caseCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
caseCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
params.caseSensitive = caseCheckbox.getSelection();
}
});
final Button fastSearchCheckbox = UIUtils.createLabelCheckbox(optionsGroup2, "Fast search (indexed)", params.fastSearch);
fastSearchCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
fastSearchCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
params.fastSearch = fastSearchCheckbox.getSelection();
}
});
final Button searchNumbersCheckbox = UIUtils.createLabelCheckbox(optionsGroup2, "Search in numbers", params.searchNumbers);
searchNumbersCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
searchNumbersCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
params.searchNumbers = searchNumbersCheckbox.getSelection();
}
});
final Button searchLOBCheckbox = UIUtils.createLabelCheckbox(optionsGroup2, "Search in LOBs", params.searchLOBs);
searchLOBCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
searchLOBCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
params.searchLOBs = searchNumbersCheckbox.getSelection();
}
});
}
final List<DBNNode> checkedNodes = new ArrayList<>();
dataSourceTree.setEnabled(false);
try {
DBeaverUI.runInProgressDialog(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Load database nodes", 1);
try {
monitor.subTask("Load tree state");
checkedNodes.addAll(loadTreeState(monitor, store, PROP_SOURCES));
} finally {
monitor.done();
}
}
});
} catch (InvocationTargetException e) {
UIUtils.showErrorDialog(getShell(), "Data sources load", "Error loading settings", e.getTargetException());
}
if (!checkedNodes.isEmpty()) {
boolean first = true;
for (DBNNode node : checkedNodes) {
((CheckboxTreeViewer) dataSourceTree.getViewer()).setChecked(node, true);
if (first) {
dataSourceTree.getViewer().reveal(NavigatorUtils.getDataSourceNode(node));
first = false;
}
}
checkboxTreeManager.updateCheckStates();
}
updateEnablement();
dataSourceTree.setEnabled(true);
}
Aggregations