Skip to content

Commit

Permalink
#5581 GIT commands state + bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-rider committed Jun 29, 2019
1 parent 8a8cf28 commit 597a580
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 58 deletions.
Expand Up @@ -39,11 +39,9 @@

import java.util.Map;

public class DataSourceAutoCommitHandler extends AbstractDataSourceHandler implements IElementUpdater
{
public class DataSourceAutoCommitHandler extends AbstractDataSourceHandler implements IElementUpdater {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException
{
public Object execute(ExecutionEvent event) throws ExecutionException {
DBCExecutionContext context = getExecutionContext(event, true);
if (context != null) {
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
Expand Down Expand Up @@ -71,8 +69,7 @@ public void run() {
}

@Override
public void updateElement(UIElement element, Map parameters)
{
public void updateElement(UIElement element, Map parameters) {
IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
return;
Expand Down
12 changes: 9 additions & 3 deletions plugins/org.jkiss.dbeaver.team.git.ui/plugin.xml
Expand Up @@ -3,7 +3,7 @@

<plugin>

<extension name="GitCommandsLabel" point="org.eclipse.ui.commands">
<extension point="org.eclipse.ui.commands">
<category id="org.jkiss.dbeaver.git.commands.category" name="Git Category"/>
<command categoryId="org.jkiss.dbeaver.git.commands.category" id="org.jkiss.dbeaver.git.commands.share" name="Share project in Git"/>
<command categoryId="org.jkiss.dbeaver.git.commands.category" id="org.jkiss.dbeaver.git.commands.projectFromGit" name="Create project from Git"/>
Expand Down Expand Up @@ -39,15 +39,18 @@
</extension>

<extension point="org.eclipse.ui.bindings">
<key commandId="org.jkiss.dbeaver.git.commands.update" schemeId="org.jkiss.dbeaver.defaultKeyScheme" sequence="CTRL+SHIFT+U"/>
<key commandId="org.jkiss.dbeaver.git.commands.commit" schemeId="org.jkiss.dbeaver.defaultKeyScheme" sequence="CTRL+SHIFT+K"/>
</extension>

<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu id="org.jkiss.dbeaver.team.git.menu" label="Git" mnemonic="M">
<command commandId="org.jkiss.dbeaver.git.commands.share" mnemonic="G"/>

<command commandId="org.jkiss.dbeaver.git.commands.update" mnemonic="L"/>
<command commandId="org.jkiss.dbeaver.git.commands.commit" mnemonic="C"/>
<separator name="projects" visible="true"/>
<command commandId="org.jkiss.dbeaver.git.commands.share" mnemonic="G"/>
<command commandId="org.jkiss.dbeaver.git.commands.projectFromGit" mnemonic="G"/>
</menu>
</menuContribution>
<menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
Expand All @@ -67,6 +70,9 @@
<menuContribution allPopups="false" locationURI="toolbar:org.jkiss.dbeaver.core.projectNavigator?before=additions">
<command commandId="org.jkiss.dbeaver.git.commands.projectFromGit"/>
</menuContribution>
<menuContribution allPopups="false" locationURI="menu:org.jkiss.dbeaver.core.projectNavigator?before=additions">
<command commandId="org.jkiss.dbeaver.git.commands.projectFromGit"/>
</menuContribution>

</extension>

Expand Down
Expand Up @@ -19,13 +19,19 @@

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.egit.ui.internal.commit.CommitUI;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.menus.UIElement;
import org.jkiss.dbeaver.team.git.ui.utils.GitUIUtils;

public class GITCommitHandler extends GITAbstractHandler {
import java.util.Map;

public class GITCommitHandler extends GITAbstractHandler implements IElementUpdater {

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
Expand All @@ -44,4 +50,12 @@ public Object execute(final ExecutionEvent event) throws ExecutionException {
return null;
}

@Override
public void updateElement(UIElement element, Map parameters) {
IProject project = GitUIUtils.extractActiveProject(element.getServiceLocator());
if (project != null) {
element.setText("Commit '" + project.getName() + "' changes to Git");
}
}

}
Expand Up @@ -20,14 +20,19 @@

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.egit.ui.internal.pull.PullOperationUI;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.menus.UIElement;
import org.jkiss.dbeaver.team.git.ui.utils.GitUIUtils;

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

public class GITUpdateHandler extends GITAbstractHandler {
public class GITUpdateHandler extends GITAbstractHandler implements IElementUpdater {


@Override
Expand All @@ -43,4 +48,12 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
}
}

@Override
public void updateElement(UIElement element, Map parameters) {
IProject project = GitUIUtils.extractActiveProject(element.getServiceLocator());
if (project != null) {
element.setText("Update '" + project.getName() + "' changes from Git");
}
}

}
Expand Up @@ -18,35 +18,35 @@

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.egit.ui.internal.sharing.SharingWizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.menus.UIElement;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.team.git.ui.utils.GitUIUtils;

public class ProjectShareHandler extends AbstractHandler {

import java.util.Map;

public class ProjectShareHandler extends AbstractHandler implements IElementUpdater {

private static final String CMD_SHARE = "org.eclipse.egit.ui.command.shareProject";

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

//IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);

public Object execute(ExecutionEvent event) {
IProject project = GitUIUtils.extractActiveProject(event);

if (project == null) {
DBWorkbench.getPlatformUI().showError(
"Nothing to share - no active project",
"Select a project or resource to share");
"Nothing to share - no active project",
"Select a project or resource to share");
return null;
}
//IHandlerService handlerService = window.getService(IHandlerService.class);
//ICommandService commandService = window.getService(ICommandService.class);
//ICommandService commandService = window.getService(ICommandService.class);

IWorkbench workbench = HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench();
SharingWizard wizard = new SharingWizard();
Expand All @@ -55,30 +55,15 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
WizardDialog wizardDialog = new WizardDialog(shell, wizard);
wizardDialog.setHelpAvailable(false);
wizardDialog.open();
/*

Command shareCommand = commandService.getCommand(CMD_SHARE);
Parameterization[] params = new Parameterization[1];
try {
params[0] = new Parameterization(shareCommand.getParameters()[0], "General");
} catch (NotDefinedException e) {
throw new ExecutionException("Error in share command parameter", e);
}
return null;
}

ParameterizedCommand pshareCommand = new ParameterizedCommand(shareCommand,
params);
try {
handlerService.executeCommand(pshareCommand, null);
} catch (Exception ex) {
DBWorkbench.getPlatformUI().showError("Error sharing a project", "Can't execute command '" + CMD_SHARE + "'", ex);
@Override
public void updateElement(UIElement element, Map parameters) {
IProject project = GitUIUtils.extractActiveProject(element.getServiceLocator());
if (project != null) {
element.setText("Add '" + project.getName() + "' to Git repository");
}
*/

return null;

}
}
}
Expand Up @@ -24,10 +24,11 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.*;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.services.IServiceLocator;
import org.jkiss.dbeaver.model.navigator.*;
import org.jkiss.dbeaver.ui.editors.EditorUtils;
import org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput;
Expand All @@ -39,18 +40,7 @@ public static IProject extractActiveProject(ExecutionEvent event) {
if (project == null) {
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (activeEditor != null) {
IEditorInput editorInput = activeEditor.getEditorInput();
if (editorInput instanceof IDatabaseEditorInput) {
DBNDatabaseNode node = ((IDatabaseEditorInput) editorInput).getNavigatorNode();
if (node != null) {
return node.getOwnerProject();
}
} else {
IFile input = EditorUtils.getFileFromInput(editorInput);
if (input != null) {
project = input.getProject();
}
}
return extractProject(activeEditor);
}
}
return project;
Expand All @@ -77,4 +67,48 @@ public static IProject extractProject(ISelection selection) {
}
}

public static IProject extractProject(IEditorPart activeEditor) {
IEditorInput editorInput = activeEditor.getEditorInput();
if (editorInput instanceof IDatabaseEditorInput) {
DBNDatabaseNode node = ((IDatabaseEditorInput) editorInput).getNavigatorNode();
if (node != null) {
return node.getOwnerProject();
}
} else {
IFile input = EditorUtils.getFileFromInput(editorInput);
if (input != null) {
return input.getProject();
}
}
return null;
}

public static IProject extractActiveProject(IServiceLocator serviceLocator) {
IWorkbenchWindow workbenchWindow = serviceLocator == null ? null : serviceLocator.getService(IWorkbenchWindow.class);
if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
return null;
}
return GitUIUtils.extractActiveProject(workbenchWindow);
}

public static IProject extractActiveProject(IWorkbenchWindow window) {
IWorkbenchPage activePage = window.getActivePage();
if (activePage != null) {
IWorkbenchPart activePart = activePage.getActivePart();
if (activePart != null) {
ISelectionProvider selectionProvider = activePart.getSite().getSelectionProvider();
if (selectionProvider != null) {
IProject project = extractProject(selectionProvider.getSelection());
if (project != null) {
return project;
}
}
}
IEditorPart activeEditor = activePage.getActiveEditor();
if (activeEditor != null) {
return extractProject(activeEditor);
}
}
return null;
}
}

0 comments on commit 597a580

Please sign in to comment.