use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class GITAbstractHandler method getRepositories.
protected Repository[] getRepositories(ExecutionEvent event) {
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
if (activePart instanceof IEditorPart) {
IFile editorFile = EditorUtils.getFileFromInput(((IEditorPart) activePart).getEditorInput());
if (editorFile != null) {
Repository repository = SelectionUtils.getRepository(new StructuredSelection(editorFile));
if (repository != null) {
return new Repository[] { repository };
}
}
}
{
INavigatorModelView navigatorModelView = GeneralUtils.adapt(activePart, INavigatorModelView.class);
if (navigatorModelView != null) {
DBNNode rootNode = navigatorModelView.getRootNode();
if (rootNode != null) {
DBPProject ownerProject = rootNode.getOwnerProject();
if (ownerProject != null) {
return getRepositories(new StructuredSelection(ownerProject.getEclipseProject()));
}
}
}
}
IStructuredSelection selection = HandlerUtil.getCurrentStructuredSelection(event);
return getRepositories(selection);
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class RecentTasksMenuContributor method fillContributionItems.
@Override
protected void fillContributionItems(final List<IContributionItem> menuItems) {
DBPProject project = NavigatorUtils.getSelectedProject();
if (project == null) {
return;
}
DBTTask[] tasks = project.getTaskManager().getAllTasks();
Arrays.sort(tasks, (o1, o2) -> {
DBTTaskRun lr1 = o1.getLastRun();
DBTTaskRun lr2 = o1.getLastRun();
if (lr1 == lr2)
return o1.getCreateTime().compareTo(o2.getCreateTime());
else if (lr1 == null)
return -1;
else if (lr2 == null)
return 1;
else
return lr1.getStartTime().compareTo(lr2.getStartTime());
});
for (int i = 0; i < tasks.length && i <= MAX_ITEMS; i++) {
DBTTask task = tasks[i];
DBPImage taskIcon = task.getType().getIcon();
if (taskIcon == null)
taskIcon = DBIcon.TREE_TASK;
menuItems.add(ActionUtils.makeActionContribution(new Action(task.getName(), DBeaverIcons.getImageDescriptor(taskIcon)) {
@Override
public void run() {
TaskHandlerRun.runTask(task);
}
}, false));
}
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class DatabaseTasksTree method refreshTasks.
private void refreshTasks() {
allTasks.clear();
for (DBPProject project : DBWorkbench.getPlatform().getWorkspace().getProjects()) {
DBTTaskManager taskManager = project.getTaskManager();
DBTTask[] tasks = taskManager.getAllTasks();
if (tasks.length == 0) {
continue;
}
Collections.addAll(allTasks, tasks);
}
allTasks.sort(Comparator.comparing(DBTTask::getName));
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class ResourcePropertyTester method test.
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (!(receiver instanceof IResource)) {
return false;
}
IResource resource = (IResource) receiver;
DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
DBPResourceHandler handler = workspace.getResourceHandler(resource);
if (handler == null) {
return false;
}
switch(property) {
case PROP_CAN_OPEN:
return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_OPEN) != 0;
case PROP_CAN_DELETE:
return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_DELETE) != 0;
case PROP_CAN_CREATE_FILE:
return handler instanceof DBPResourceCreator && (handler.getFeatures(resource) & DBPResourceCreator.FEATURE_CREATE_FILE) != 0;
case PROP_CAN_CREATE_FOLDER:
return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_CREATE_FOLDER) != 0;
case PROP_CAN_CREATE_LINK:
return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_CREATE_FOLDER) != 0 && !resource.isLinked(IResource.CHECK_ANCESTORS);
case PROP_CAN_SET_ACTIVE:
{
DBPProject activeProject = workspace.getActiveProject();
return resource instanceof IProject && (activeProject == null || resource != activeProject.getEclipseProject());
}
case PROP_TYPE:
final DBPResourceHandler resourceHandler = DBWorkbench.getPlatform().getWorkspace().getResourceHandler(resource);
return resourceHandler != null && expectedValue.equals(resourceHandler.getTypeName(resource));
}
return false;
}
use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.
the class EditorUtils method getInputContextDefaults.
/**
* String[2] = { defaultCatalogName, defaultSchema }
*/
public static String[] getInputContextDefaults(DBPDataSourceContainer dataSource, IEditorInput editorInput) {
String defaultDatasource = null;
String defaultCatalogName = null;
String defaultSchema = null;
if (editorInput instanceof INonPersistentEditorInput) {
defaultDatasource = (String) ((INonPersistentEditorInput) editorInput).getProperty(PROP_CONTEXT_DEFAULT_DATASOURCE);
defaultCatalogName = (String) ((INonPersistentEditorInput) editorInput).getProperty(PROP_CONTEXT_DEFAULT_CATALOG);
defaultSchema = (String) ((INonPersistentEditorInput) editorInput).getProperty(PROP_CONTEXT_DEFAULT_SCHEMA);
} else {
IFile file = getFileFromInput(editorInput);
if (file != null) {
DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(file.getProject());
if (projectMeta != null) {
defaultDatasource = (String) projectMeta.getResourceProperty(file, PROP_CONTEXT_DEFAULT_DATASOURCE);
defaultCatalogName = (String) projectMeta.getResourceProperty(file, PROP_CONTEXT_DEFAULT_CATALOG);
defaultSchema = (String) projectMeta.getResourceProperty(file, PROP_CONTEXT_DEFAULT_SCHEMA);
}
} else {
File localFile = getLocalFileFromInput(editorInput);
if (localFile != null) {
final DBPExternalFileManager efManager = DBWorkbench.getPlatform().getExternalFileManager();
defaultDatasource = (String) efManager.getFileProperty(localFile, PROP_CONTEXT_DEFAULT_DATASOURCE);
defaultCatalogName = (String) efManager.getFileProperty(localFile, PROP_CONTEXT_DEFAULT_CATALOG);
defaultSchema = (String) efManager.getFileProperty(localFile, PROP_CONTEXT_DEFAULT_SCHEMA);
}
}
}
if (!CommonUtils.isEmpty(defaultDatasource) && !defaultDatasource.equals(dataSource.getId())) {
// Wrong datasource
return new String[] { null, null };
}
return new String[] { defaultCatalogName, defaultSchema };
}
Aggregations