use of org.apache.hop.ui.core.dialog.EnterSelectionDialog in project hop by apache.
the class ColumnExistsDialog method getSchemaNames.
private void getSchemaNames() {
if (wSchemaname.isDisposed()) {
return;
}
DatabaseMeta databaseMeta = pipelineMeta.findDatabase(wConnection.getText());
if (databaseMeta != null) {
Database database = new Database(loggingObject, variables, databaseMeta);
try {
database.connect();
String[] schemas = database.getSchemas();
if (null != schemas && schemas.length > 0) {
schemas = Const.sortStrings(schemas);
EnterSelectionDialog dialog = new EnterSelectionDialog(shell, schemas, BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.Title", wConnection.getText()), BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.Message"));
String d = dialog.open();
if (d != null) {
wSchemaname.setText(Const.NVL(d, ""));
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.Empty.Message"));
mb.setText(BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.Empty.Title"));
mb.open();
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.ConnectionError"), e);
} finally {
if (database != null) {
database.disconnect();
database = null;
}
}
}
}
use of org.apache.hop.ui.core.dialog.EnterSelectionDialog in project hop by apache.
the class UIGitTest method testPush.
@Test
public void testPush() throws Exception {
// Set remote
Git git2 = new Git(db2);
UIGit uiGit2 = new UIGit();
uiGit2.setGit(git2);
URIish uri = new URIish(db2.getDirectory().toURI().toURL());
RemoteAddCommand cmd = git.remoteAdd();
cmd.setName(Constants.DEFAULT_REMOTE_NAME);
cmd.setUri(uri);
cmd.call();
assertTrue(uiGit.hasRemote());
// create some refs via commits and tag
RevCommit commit = git.commit().setMessage("initial commit").call();
Ref tagRef = git.tag().setName("tag").call();
try {
db2.resolve(commit.getId().getName() + "^{commit}");
fail("id shouldn't exist yet");
} catch (MissingObjectException e) {
// we should get here
}
boolean success = uiGit.push();
assertTrue(success);
assertEquals(commit.getId(), db2.resolve(commit.getId().getName() + "^{commit}"));
assertEquals(tagRef.getObjectId(), db2.resolve(tagRef.getObjectId().getName()));
// Push a tag
EnterSelectionDialog esd = mock(EnterSelectionDialog.class);
doReturn("tag").when(esd).open();
doReturn(esd).when(uiGit).getEnterSelectionDialog(any(), anyString(), anyString());
uiGit.push(VCS.TYPE_TAG);
assertTrue(success);
assertTrue(uiGit2.getTags().contains("tag"));
// Another commit and push a branch again
writeTrashFile("Test2.txt", "Hello world");
git.add().addFilepattern("Test2.txt").call();
commit = git.commit().setMessage("second commit").call();
doReturn(Constants.MASTER).when(esd).open();
uiGit.push(VCS.TYPE_BRANCH);
assertTrue(success);
assertEquals(commit.getId(), db2.resolve(commit.getId().getName() + "^{commit}"));
assertEquals("refs/remotes/origin/master", uiGit.getExpandedName("origin/master", "branch"));
}
use of org.apache.hop.ui.core.dialog.EnterSelectionDialog in project hop by apache.
the class UIGit method push.
public boolean push(String type) throws HopException {
if (!hasRemote()) {
throw new HopException("There is no remote set up to push to. Please set this up.");
}
String name = null;
List<String> names;
EnterSelectionDialog esd;
switch(type) {
case VCS.TYPE_BRANCH:
names = getLocalBranches();
esd = getEnterSelectionDialog(names.toArray(new String[names.size()]), "Select Branch", "Select the branch to push...");
name = esd.open();
if (name == null) {
return false;
}
break;
case VCS.TYPE_TAG:
names = getTags();
esd = getEnterSelectionDialog(names.toArray(new String[names.size()]), "Select Tag", "Select the tag to push...");
name = esd.open();
if (name == null) {
return false;
}
break;
}
try {
name = name == null ? null : getExpandedName(name, type);
PushCommand cmd = git.push();
cmd.setCredentialsProvider(credentialsProvider);
if (name != null) {
cmd.setRefSpecs(new RefSpec(name));
}
Iterable<PushResult> resultIterable = cmd.call();
processPushResult(resultIterable);
return true;
} catch (TransportException e) {
if (e.getMessage().contains("Authentication is required but no CredentialsProvider has been registered") || e.getMessage().contains("not authorized")) {
// when the cached credential does not work
if (promptUsernamePassword()) {
return push(type);
}
} else {
throw new HopException("There was an error doing a git push", e);
}
} catch (Exception e) {
throw new HopException("There was an error doing a git push", e);
}
return false;
}
use of org.apache.hop.ui.core.dialog.EnterSelectionDialog in project hop by apache.
the class AddSequenceDialog method getSchemaNames.
private void getSchemaNames() {
if (wSchema.isDisposed()) {
return;
}
DatabaseMeta databaseMeta = pipelineMeta.findDatabase(wConnection.getText(), variables);
if (databaseMeta != null) {
Database database = new Database(loggingObject, variables, databaseMeta);
try {
database.connect();
String[] schemas = database.getSchemas();
if (null != schemas && schemas.length > 0) {
schemas = Const.sortStrings(schemas);
EnterSelectionDialog dialog = new EnterSelectionDialog(shell, schemas, BaseMessages.getString(PKG, "AddSequenceDialog.SelectSequence.Title", wConnection.getText()), BaseMessages.getString(PKG, "AddSequenceDialog.SelectSequence.Message"));
String d = dialog.open();
if (d != null) {
wSchema.setText(Const.NVL(d.toString(), ""));
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "AddSequenceDialog.NoSchema.Message"));
mb.setText(BaseMessages.getString(PKG, "AddSequenceDialog.NoSchema.Title"));
mb.open();
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "AddSequenceDialog.ErrorGettingSchemas"), e);
} finally {
if (database != null) {
database.disconnect();
database = null;
}
}
}
}
use of org.apache.hop.ui.core.dialog.EnterSelectionDialog in project hop by apache.
the class GitGuiPlugin method gitCommit.
@GuiToolbarElement(root = ExplorerPerspective.GUI_PLUGIN_TOOLBAR_PARENT_ID, id = TOOLBAR_ITEM_COMMIT, toolTip = "i18n::GitGuiPlugin.Toolbar.Commit.Tooltip", image = "git-commit.svg")
public void gitCommit() {
try {
// Ask the user to select the list of changed files in the commit...
//
ExplorerFile explorerFile = getSelectedFile();
if (git == null || explorerFile == null) {
return;
}
String relativePath = calculateRelativePath(git.getDirectory(), explorerFile);
if (relativePath == null) {
return;
}
List<String> changedFiles = git.getRevertPathFiles(relativePath);
if (changedFiles.isEmpty()) {
MessageBox box = new MessageBox(HopGui.getInstance().getShell(), SWT.OK | SWT.ICON_INFORMATION);
box.setText(BaseMessages.getString(PKG, "GitGuiPlugin.Dialog.NoFilesToCommit.Header"));
box.setMessage(BaseMessages.getString(PKG, "GitGuiPlugin.Dialog.NoFilesToCommit.Message"));
box.open();
} else {
String[] files = changedFiles.toArray(new String[0]);
int[] selectedIndexes = new int[files.length];
for (int i = 0; i < files.length; i++) {
selectedIndexes[i] = i;
}
EnterSelectionDialog selectionDialog = new EnterSelectionDialog(HopGui.getInstance().getShell(), files, "Select files to commit", "Please select the files to commit. They'll be staged (add) for the commit to git:");
selectionDialog.setMulti(true);
// Select all files by default
//
selectionDialog.setSelectedNrs(selectedIndexes);
String selection = selectionDialog.open();
if (selection != null) {
EnterStringDialog enterStringDialog = new EnterStringDialog(HopGui.getInstance().getShell(), BaseMessages.getString(PKG, "GitGuiPlugin.Dialog.SelectFilesToCommit.Header"), BaseMessages.getString(PKG, "GitGuiPlugin.Dialog.SelectFilesToCommit.Message"), "");
String message = enterStringDialog.open();
if (message != null) {
// Now stage/add the selected files and commit...
//
int[] selectedNrs = selectionDialog.getSelectionIndeces();
for (int selectedNr : selectedNrs) {
// If the file is gone, git.rm(), otherwise add()
//
String file = files[selectedNr];
if (fileExists(file)) {
git.add(file);
} else {
git.rm(file);
}
}
// Standard author by default
//
String authorName = git.getAuthorName(VCS.WORKINGTREE);
// Commit...
//
git.commit(authorName, message);
}
}
}
// Refresh the tree, change colors...
//
ExplorerPerspective.getInstance().refresh();
enableButtons();
} catch (Exception e) {
new ErrorDialog(HopGui.getInstance().getShell(), BaseMessages.getString(PKG, "GitGuiPlugin.Dialog.CommitError.Header"), BaseMessages.getString(PKG, "GitGuiPlugin.Dialog.CommitError.Message"), e);
}
}
Aggregations