Search in sources :

Example 6 with EnterSelectionDialog

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;
            }
        }
    }
}
Also used : Database(org.apache.hop.core.database.Database) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) EnterSelectionDialog(org.apache.hop.ui.core.dialog.EnterSelectionDialog) HopException(org.apache.hop.core.exception.HopException)

Example 7 with EnterSelectionDialog

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"));
}
Also used : URIish(org.eclipse.jgit.transport.URIish) Ref(org.eclipse.jgit.lib.Ref) Git(org.eclipse.jgit.api.Git) RemoteAddCommand(org.eclipse.jgit.api.RemoteAddCommand) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) EnterSelectionDialog(org.apache.hop.ui.core.dialog.EnterSelectionDialog) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 8 with EnterSelectionDialog

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;
}
Also used : HopException(org.apache.hop.core.exception.HopException) TransportException(org.eclipse.jgit.api.errors.TransportException) EnterSelectionDialog(org.apache.hop.ui.core.dialog.EnterSelectionDialog) URISyntaxException(java.net.URISyntaxException) HopException(org.apache.hop.core.exception.HopException) HopFileException(org.apache.hop.core.exception.HopFileException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) TransportException(org.eclipse.jgit.api.errors.TransportException)

Example 9 with EnterSelectionDialog

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;
            }
        }
    }
}
Also used : Database(org.apache.hop.core.database.Database) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) EnterSelectionDialog(org.apache.hop.ui.core.dialog.EnterSelectionDialog)

Example 10 with EnterSelectionDialog

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);
    }
}
Also used : ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) EnterStringDialog(org.apache.hop.ui.core.dialog.EnterStringDialog) EnterSelectionDialog(org.apache.hop.ui.core.dialog.EnterSelectionDialog) HopFileException(org.apache.hop.core.exception.HopFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) MessageBox(org.eclipse.swt.widgets.MessageBox) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Aggregations

EnterSelectionDialog (org.apache.hop.ui.core.dialog.EnterSelectionDialog)55 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)43 HopException (org.apache.hop.core.exception.HopException)28 DatabaseMeta (org.apache.hop.core.database.DatabaseMeta)20 Database (org.apache.hop.core.database.Database)19 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)19 IRowMeta (org.apache.hop.core.row.IRowMeta)18 IVariables (org.apache.hop.core.variables.IVariables)17 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)15 BaseTransformMeta (org.apache.hop.pipeline.transform.BaseTransformMeta)11 FormAttachment (org.eclipse.swt.layout.FormAttachment)11 FormData (org.eclipse.swt.layout.FormData)11 FormLayout (org.eclipse.swt.layout.FormLayout)11 Const (org.apache.hop.core.Const)10 BaseMessages (org.apache.hop.i18n.BaseMessages)10 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)10 BaseDialog (org.apache.hop.ui.core.dialog.BaseDialog)10 BaseTransformDialog (org.apache.hop.ui.pipeline.transform.BaseTransformDialog)10 SWT (org.eclipse.swt.SWT)10 org.eclipse.swt.widgets (org.eclipse.swt.widgets)10