Skip to content

Commit

Permalink
Git improvements, apache#2634
Browse files Browse the repository at this point in the history
- Show branch name in file explorer
- Give a message when authentication fails
- Give a message when Pull was successful
- Give a message when revert was successful
  • Loading branch information
hansva committed Oct 15, 2024
1 parent f991def commit 233de0a
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ public void gitPull() {
try {
git.pull();
ExplorerPerspective.getInstance().refresh();
MessageBox pullSuccessful =
new MessageBox(HopGui.getInstance().getShell(), SWT.ICON_INFORMATION);
pullSuccessful.setText(
BaseMessages.getString(PKG, "GitGuiPlugin.Dialog.PullSuccessful.Header"));
pullSuccessful.setMessage(
BaseMessages.getString(PKG, "GitGuiPlugin.Dialog.PullSuccessful.Message"));
pullSuccessful.open();
} catch (Exception e) {
new ErrorDialog(
HopGui.getInstance().getShell(),
Expand Down Expand Up @@ -361,6 +368,11 @@ public void gitRevert() {
git.revertPath(file);
}
}
MessageBox box =
new MessageBox(HopGui.getInstance().getShell(), SWT.OK | SWT.ICON_INFORMATION);
box.setText(BaseMessages.getString(PKG, "GitGuiPlugin.Dialog.FilesReverted.Header"));
box.setMessage(BaseMessages.getString(PKG, "GitGuiPlugin.Dialog.FilesReverted.Message"));
box.open();
}
} catch (Exception e) {
new ErrorDialog(
Expand Down Expand Up @@ -408,7 +420,9 @@ public void rootChanged(String rootFolder, String rootName) {
if (gitConfig.exists()) {
git = new UIGit();
git.openRepo(rootFolder);
LogChannel.UI.logBasic("Found git project for: " + rootFolder);
ExplorerPerspective.getInstance().setRootName(rootName + " (" + git.getBranch() + ")");
} else {
git = null;
}
} catch (Exception e) {
// This is not a git project...
Expand Down Expand Up @@ -525,7 +539,7 @@ public void filePainted(Tree tree, TreeItem treeItem, String path, String name)
treeItem.setForeground(colorStaged);
break;
case ADD:
if (file.getIsStaged()) {
if (Boolean.TRUE.equals(file.getIsStaged())) {
treeItem.setForeground(colorStaged);
} else {
treeItem.setForeground(colorUnstaged);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.hop.git.model.revision.ObjectRevision;
import org.apache.hop.i18n.BaseMessages;
import org.apache.hop.ui.core.dialog.EnterSelectionDialog;
import org.apache.hop.ui.core.dialog.ErrorDialog;
import org.apache.hop.ui.hopgui.HopGui;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.DiffCommand;
Expand Down Expand Up @@ -523,6 +524,13 @@ public boolean pull() throws HopException {
CONST_AUTHENTICATION_IS_REQUIRED_BUT_NO_CREDENTIALS_PROVIDER_HAS_BEEN_REGISTERED)
|| e.getMessage()
.contains(CONST_NOT_AUTHORIZED)) { // when the cached credential does not work
if (e.getMessage().contains(CONST_NOT_AUTHORIZED)) {
new ErrorDialog(
HopGui.getInstance().getShell(),
"Git Error",
"Error Authenticating to Git service",
e);
}
if (promptUsernamePassword()) {
return pull();
}
Expand Down
22 changes: 6 additions & 16 deletions plugins/misc/git/src/main/java/org/apache/hop/git/model/VCS.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.hop.git.model;

import org.apache.hop.ui.core.dialog.EnterStringDialog;
import org.apache.hop.ui.core.dialog.EnterUsernamePasswordDialog;
import org.apache.hop.ui.core.dialog.MessageBox;
import org.apache.hop.ui.hopgui.HopGui;
import org.eclipse.swt.SWT;
Expand Down Expand Up @@ -47,24 +47,14 @@ void showMessageBox(String title, String message) {
* @return true on success
*/
protected boolean promptUsernamePassword() {
EnterStringDialog userDialog =
new EnterStringDialog(
HopGui.getInstance().getShell(), "", "Username?", "Enter the git username to use");
String username = userDialog.open();
if (username == null) {
EnterUsernamePasswordDialog userDialog =
new EnterUsernamePasswordDialog(HopGui.getInstance().getShell());
String[] usernamePassword = userDialog.open();
if (usernamePassword == null) {
return false;
}

EnterStringDialog passDialog =
new EnterStringDialog(
HopGui.getInstance().getShell(), "", "Password?", "Enter the git password to use");
passDialog.setEchoChar('*');
String password = passDialog.open();
if (password == null) {
return false;
}

setCredential(username, password);
setCredential(usernamePassword[0], usernamePassword[1]);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ GitGuiPlugin.Dialog.RevertFiles.Header=Select files to revert
GitGuiPlugin.Dialog.RevertFiles.Message=Please select the files to revert
GitGuiPlugin.Dialog.SelectFilesToCommit.Header=Commit Message
GitGuiPlugin.Dialog.SelectFilesToCommit.Message=Please enter a commit message:
GitGuiPlugin.Dialog.PullSuccessful.Header=Successful Pull
GitGuiPlugin.Dialog.PullSuccessful.Message=Successful Pull
GitGuiPlugin.Dialog.FilesReverted.Header=Files Reverted
GitGuiPlugin.Dialog.FilesReverted.Message=Files Reverted
GitGuiPlugin.Info.Label=Git Info: {0}
GitGuiPlugin.Menu.Add.Text=Git Add
GitGuiPlugin.Menu.Commit.Text=Git Commit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hop.ui.core.dialog;

import org.apache.hop.i18n.BaseMessages;
import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.core.gui.GuiResource;
import org.apache.hop.ui.core.gui.WindowProperty;
import org.apache.hop.ui.pipeline.transform.BaseTransformDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/** This dialog allows you to enter a (single line) String. */
public class EnterUsernamePasswordDialog extends Dialog {
private static final Class<?> PKG = EnterUsernamePasswordDialog.class;

private Text wUsername;
private Text wPassword;

private Button wOk;

private Shell shell;

private PropsUi props;

private boolean mandatory;

String[] returnValues;

/**
* Constructs with the ability to use environmental variable substitution.
*
* @param parent Parent gui object
*/
public EnterUsernamePasswordDialog(Shell parent) {
super(parent, SWT.NONE);
this.props = PropsUi.getInstance();
}

public String[] open() {
Shell parent = getParent();
Control lastControl;

shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL | SWT.SHEET);
PropsUi.setLook(shell);

FormLayout formLayout = new FormLayout();
formLayout.marginWidth = PropsUi.getFormMargin();
formLayout.marginHeight = PropsUi.getFormMargin();

shell.setLayout(formLayout);
shell.setImage(GuiResource.getInstance().getImageHopUi());
shell.setText("Username/Password");

int middle = props.getMiddlePct();
int margin = PropsUi.getMargin();

// The Username line...
Label wlUsername = new Label(shell, SWT.RIGHT);
wlUsername.setText("Username:");
PropsUi.setLook(wlUsername);
FormData fdlUsername = new FormData();
fdlUsername.left = new FormAttachment(0, 0);
fdlUsername.top = new FormAttachment(0, 0);
fdlUsername.right = new FormAttachment(middle, -margin);
wlUsername.setLayoutData(fdlUsername);
wUsername = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
PropsUi.setLook(wUsername);

FormData fdUsername = new FormData();
fdUsername.left = new FormAttachment(wlUsername, 0);
fdUsername.top = new FormAttachment(0, 0);
fdUsername.right = new FormAttachment(100, -margin);
wUsername.setLayoutData(fdUsername);

// The Password line...
Label wlPassword = new Label(shell, SWT.RIGHT);
wlPassword.setText("Password:");
PropsUi.setLook(wlPassword);
FormData fdlPassword = new FormData();
fdlPassword.left = new FormAttachment(0, 0);
fdlPassword.top = new FormAttachment(wlUsername, margin * 2);
fdlPassword.right = new FormAttachment(middle, -margin);
wlPassword.setLayoutData(fdlPassword);
wPassword = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER | SWT.PASSWORD);
PropsUi.setLook(wPassword);
lastControl = wPassword;

FormData fdPassword = new FormData();
fdPassword.left = new FormAttachment(wlPassword, 0);
fdPassword.top = new FormAttachment(wlUsername, margin * 2);
fdPassword.right = new FormAttachment(100, -margin);
wPassword.setLayoutData(fdPassword);

// Some buttons
wOk = new Button(shell, SWT.PUSH);
wOk.setText(BaseMessages.getString(PKG, "System.Button.OK"));
Button wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));

BaseTransformDialog.positionBottomButtons(
shell, new Button[] {wOk, wCancel}, margin, lastControl);

// Add listeners
wOk.addListener(SWT.Selection, e -> ok());
wCancel.addListener(SWT.Selection, e -> cancel());

BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel());

return returnValues;
}

public void dispose() {
props.setScreen(new WindowProperty(shell));
shell.dispose();
}

private void cancel() {
dispose();
}

private void ok() {
returnValues = new String[] {wUsername.getText(), wPassword.getText()};
dispose();
}

/**
* @return the mandatory
*/
public boolean isMandatory() {
return mandatory;
}

/**
* @param mandatory the manditory to set
*/
public void setMandatory(boolean mandatory) {
this.mandatory = mandatory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1659,4 +1659,8 @@ public List<IExplorerSelectionListener> getSelectionListeners() {
public Tree getTree() {
return tree;
}

public void setRootName(String rootName) {
this.rootName = rootName;
}
}

0 comments on commit 233de0a

Please sign in to comment.