Search in sources :

Example 1 with JideToggleButton

use of com.jidesoft.swing.JideToggleButton in project oxygen-git-client-addon by oxygenxml.

the class CommitAndStatusPanel method addAmendLastCommitToggle.

/**
 * Add the toggle that allows amending the last commit.
 *
 * @param toolbar The toolbar to which to add.
 */
private void addAmendLastCommitToggle(JToolBar toolbar) {
    amendLastCommitToggle = new JideToggleButton(Icons.getIcon(Icons.AMEND_COMMIT));
    amendLastCommitToggle.setFocusPainted(false);
    amendLastCommitToggle.setToolTipText(translator.getTranslation(Tags.AMEND_LAST_COMMIT));
    amendLastCommitToggle.addItemListener(new ItemListener() {

        String previousText = "";

        @Override
        public void itemStateChanged(ItemEvent ev) {
            if (ev.getStateChange() == ItemEvent.SELECTED) {
                treatAmendEnabled();
            } else {
                commitMessageArea.setText(previousText);
                toggleCommitButtonAndUpdateMessageArea(false);
                commitButton.setText(translator.getTranslation(Tags.COMMIT));
            }
        }

        /**
         * Amend was enabled. Treat the event.
         */
        private void treatAmendEnabled() {
            previousText = commitMessageArea.getText();
            try {
                if (gitAccess.getPushesAhead() == 0) {
                    int result = PluginWorkspaceProvider.getPluginWorkspace().showConfirmDialog(translator.getTranslation(Tags.AMEND_LAST_COMMIT), translator.getTranslation(Tags.AMEND_PUSHED_COMMIT_WARNING), new String[] { "   " + translator.getTranslation(Tags.YES) + "   ", "   " + translator.getTranslation(Tags.NO) + "   " }, new int[] { 1, 0 });
                    if (result == 1) {
                        prepareAmend();
                    } else {
                        amendLastCommitToggle.setSelected(false);
                    }
                } else {
                    prepareAmend();
                }
            } catch (RepoNotInitializedException e) {
                PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(e.getMessage());
            }
        }

        /**
         * Prepare amend.
         */
        private void prepareAmend() {
            RevCommit latestCommitOnBranch = null;
            try {
                latestCommitOnBranch = GitAccess.getInstance().getLatestCommitOnCurrentBranch();
            } catch (GitAPIException | IOException | NoRepositorySelected e) {
                LOGGER.error(e.getMessage(), e);
            }
            if (latestCommitOnBranch != null) {
                String text = latestCommitOnBranch.getFullMessage();
                commitMessageArea.setText(text);
                toggleCommitButtonAndUpdateMessageArea(false);
                commitButton.setText(translator.getTranslation(Tags.AMEND_LAST_COMMIT));
            }
        }
    });
    toolbar.add(amendLastCommitToggle);
}
Also used : ItemEvent(java.awt.event.ItemEvent) JideToggleButton(com.jidesoft.swing.JideToggleButton) ItemListener(java.awt.event.ItemListener) RepoNotInitializedException(com.oxygenxml.git.service.RepoNotInitializedException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with JideToggleButton

use of com.jidesoft.swing.JideToggleButton in project oxygen-git-client-addon by oxygenxml.

the class CommitAndStatusPanel method addAutoPushOnCommitToggle.

/**
 * Add the toggle that controls whether or not to automatically push on commit.
 *
 * @param toolbar The toolbar to which to add.
 */
private void addAutoPushOnCommitToggle(JToolBar toolbar) {
    autoPushWhenCommittingToggle = new JideToggleButton(Icons.getIcon(Icons.AUTO_PUSH_ON_COMMIT));
    autoPushWhenCommittingToggle.setFocusPainted(false);
    autoPushWhenCommittingToggle.setToolTipText(translator.getTranslation(Tags.PUSH_WHEN_COMMITTING));
    autoPushWhenCommittingToggle.setSelected(OptionsManager.getInstance().isAutoPushWhenCommitting());
    autoPushWhenCommittingToggle.addItemListener(ev -> OptionsManager.getInstance().setAutoPushWhenCommitting(ev.getStateChange() == ItemEvent.SELECTED));
    toolbar.add(autoPushWhenCommittingToggle);
}
Also used : JideToggleButton(com.jidesoft.swing.JideToggleButton)

Example 3 with JideToggleButton

use of com.jidesoft.swing.JideToggleButton in project oxygen-git-client-addon by oxygenxml.

the class FlatView5Test method testAmendCommitThatWasNotPushed_editCommitMessage.

/**
 * <p><b>Description:</b> Amend commit that was not yet pushed. Edit only the commit message.</p>
 * <p><b>Bug ID:</b> EXM-41392</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testAmendCommitThatWasNotPushed_editCommitMessage() throws Exception {
    String localTestRepository = "target/test-resources/testAmendCommitThatWasNotPushed_editCommitMessage_local";
    String remoteTestRepository = "target/test-resources/testAmendCommitThatWasNotPushed_editCommitMessage_remote";
    // Create repositories
    Repository remoteRepo = createRepository(remoteTestRepository);
    Repository localRepo = createRepository(localTestRepository);
    bindLocalToRemote(localRepo, remoteRepo);
    pushOneFileToRemote(localTestRepository, "init.txt", "hello");
    flushAWT();
    // Create a new file
    new File(localTestRepository).mkdirs();
    createNewFile(localTestRepository, "test.txt", "content");
    // Stage
    add(new FileStatus(GitChangeType.ADD, "test.txt"));
    // No amend by default
    CommitAndStatusPanel commitPanel = stagingPanel.getCommitPanel();
    JideToggleButton amendBtn = commitPanel.getAmendLastCommitToggle();
    assertFalse(amendBtn.isSelected());
    // Commit the test file
    assertEquals(0, GitAccess.getInstance().getPushesAhead());
    SwingUtilities.invokeAndWait(() -> {
        commitPanel.getCommitMessageArea().setText("FIRST COMMIT MESSAGE");
        commitPanel.getCommitButton().doClick();
    });
    waitForScheluerBetter();
    assertEquals(1, GitAccess.getInstance().getPushesAhead());
    RevCommit firstCommit = getLastCommit();
    assertFalse(commitPanel.getCommitButton().isEnabled());
    SwingUtilities.invokeLater(() -> amendBtn.setSelected(true));
    flushAWT();
    assertTrue(amendBtn.isSelected());
    assertEquals("FIRST COMMIT MESSAGE", commitPanel.getCommitMessageArea().getText());
    SwingUtilities.invokeLater(() -> amendBtn.setSelected(false));
    flushAWT();
    assertFalse(amendBtn.isSelected());
    assertEquals("", commitPanel.getCommitMessageArea().getText());
    SwingUtilities.invokeLater(() -> amendBtn.setSelected(true));
    waitForScheluerBetter();
    flushAWT();
    assertTrue(amendBtn.isSelected());
    assertEquals("FIRST COMMIT MESSAGE", commitPanel.getCommitMessageArea().getText());
    assertTrue(commitPanel.getCommitButton().isEnabled());
    SwingUtilities.invokeLater(() -> commitPanel.getCommitMessageArea().setText("EDITED MESSAGE"));
    SwingUtilities.invokeLater(() -> commitPanel.getCommitButton().doClick());
    waitForScheluerBetter();
    flushAWT();
    assertEquals(1, GitAccess.getInstance().getPushesAhead());
    assertFalse(amendBtn.isSelected());
    assertEquals("", commitPanel.getCommitMessageArea().getText());
    RevCommit lastCommit = getLastCommit();
    final List<DiffEntry> diffs = GitAccess.getInstance().getGit().diff().setOldTree(prepareTreeParser(GitAccess.getInstance().getRepository(), firstCommit.getName())).setNewTree(prepareTreeParser(GitAccess.getInstance().getRepository(), lastCommit.getName())).call();
    assertEquals(0, diffs.size());
    assertEquals("EDITED MESSAGE", lastCommit.getFullMessage());
}
Also used : Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JideToggleButton(com.jidesoft.swing.JideToggleButton) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DiffEntry(org.eclipse.jgit.diff.DiffEntry)

Example 4 with JideToggleButton

use of com.jidesoft.swing.JideToggleButton in project oxygen-git-client-addon by oxygenxml.

the class FlatView8Test method testAmendCommitThatWasNotPushed_editFileContent.

/**
 * <p><b>Description:</b> Amend commit that was not yet pushed. Edit the file content.</p>
 * <p><b>Bug ID:</b> EXM-41392</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
@Test
public void testAmendCommitThatWasNotPushed_editFileContent() throws Exception {
    String localTestRepository = "target/test-resources/testAmendCommitThatWasNotPushed_editFileContent_local";
    String remoteTestRepository = "target/test-resources/testAmendCommitThatWasNotPushed_editFileContent_remote";
    // Create repositories
    Repository remoteRepo = createRepository(remoteTestRepository);
    Repository localRepo = createRepository(localTestRepository);
    bindLocalToRemote(localRepo, remoteRepo);
    pushOneFileToRemote(localTestRepository, "init.txt", "hello");
    flushAWT();
    // Create a new file
    new File(localTestRepository).mkdirs();
    File file = createNewFile(localTestRepository, "test.txt", "content");
    // Stage
    add(new FileStatus(GitChangeType.ADD, "test.txt"));
    // No amend by default
    CommitAndStatusPanel commitPanel = stagingPanel.getCommitPanel();
    JideToggleButton amendBtn = commitPanel.getAmendLastCommitToggle();
    assertFalse(amendBtn.isSelected());
    // Commit the test file
    assertEquals(0, GitAccess.getInstance().getPushesAhead());
    SwingUtilities.invokeLater(() -> {
        commitPanel.getCommitMessageArea().setText("FIRST COMMIT MESSAGE");
        commitPanel.getCommitButton().doClick();
    });
    waitForScheluerBetter();
    assertEquals(1, GitAccess.getInstance().getPushesAhead());
    RevCommit firstCommit = getLastCommit();
    assertFalse(commitPanel.getCommitButton().isEnabled());
    // Change the file again.
    setFileContent(file, "modified");
    add(new FileStatus(GitChangeType.ADD, "test.txt"));
    SwingUtilities.invokeLater(() -> commitPanel.getCommitMessageArea().setText("REPLACE THIS, PLEASE"));
    flushAWT();
    SwingUtilities.invokeLater(() -> amendBtn.setSelected(true));
    flushAWT();
    assertTrue(amendBtn.isSelected());
    assertEquals("FIRST COMMIT MESSAGE", commitPanel.getCommitMessageArea().getText());
    SwingUtilities.invokeLater(() -> amendBtn.setSelected(false));
    flushAWT();
    assertFalse(amendBtn.isSelected());
    assertEquals("REPLACE THIS, PLEASE", commitPanel.getCommitMessageArea().getText());
    SwingUtilities.invokeLater(() -> amendBtn.setSelected(true));
    waitForScheluerBetter();
    flushAWT();
    assertTrue(amendBtn.isSelected());
    assertEquals("FIRST COMMIT MESSAGE", commitPanel.getCommitMessageArea().getText());
    SwingUtilities.invokeLater(() -> commitPanel.getCommitButton().doClick());
    waitForScheluerBetter();
    flushAWT();
    sleep(500);
    assertEquals(1, GitAccess.getInstance().getPushesAhead());
    assertFalse(amendBtn.isSelected());
    assertEquals("", commitPanel.getCommitMessageArea().getText());
    RevCommit lastCommit = getLastCommit();
    final List<DiffEntry> diffs = GitAccess.getInstance().getGit().diff().setOldTree(prepareTreeParser(GitAccess.getInstance().getRepository(), firstCommit.getName())).setNewTree(prepareTreeParser(GitAccess.getInstance().getRepository(), lastCommit.getName())).call();
    assertEquals(1, diffs.size());
    DiffEntry diffEntry = diffs.get(0);
    assertEquals("DiffEntry[MODIFY test.txt]", diffEntry.toString());
}
Also used : Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JideToggleButton(com.jidesoft.swing.JideToggleButton) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DiffEntry(org.eclipse.jgit.diff.DiffEntry) Test(org.junit.Test)

Example 5 with JideToggleButton

use of com.jidesoft.swing.JideToggleButton in project oxygen-git-client-addon by oxygenxml.

the class FlatViewTest method testAutoPushWhenCommit.

/**
 * <p><b>Description:</b> Automatically push when committing.</p>
 * <p><b>Bug ID:</b> EXM-44915</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testAutoPushWhenCommit() throws Exception {
    String localTestRepository = "target/test-resources/testAutoPushWhenCommit_local";
    String remoteTestRepository = "target/test-resources/testAutoPushWhenCommit_remote";
    // Create repositories
    Repository remoteRepo = createRepository(remoteTestRepository);
    Repository localRepo = createRepository(localTestRepository);
    bindLocalToRemote(localRepo, remoteRepo);
    sleep(500);
    pushOneFileToRemote(localTestRepository, "test_second_local.txt", "hellllo");
    flushAWT();
    // Create a new file
    new File(localTestRepository).mkdirs();
    File file = createNewFile(localTestRepository, "test.txt", "content");
    // Stage
    add(new FileStatus(GitChangeType.ADD, "test.txt"));
    flushAWT();
    // No auto push
    JideToggleButton autoPushBtn = stagingPanel.getCommitPanel().getAutoPushWhenCommittingToggle();
    assertFalse(autoPushBtn.isSelected());
    assertEquals(0, GitAccess.getInstance().getPushesAhead());
    SwingUtilities.invokeAndWait(() -> {
        stagingPanel.getCommitPanel().getCommitMessageArea().setText("Commit message");
        stagingPanel.getCommitPanel().getCommitButton().doClick();
    });
    waitForScheluerBetter();
    sleep(1000);
    flushAWT();
    assertEquals(1, GitAccess.getInstance().getPushesAhead());
    // Change the file again.
    setFileContent(file, "modified again");
    add(new FileStatus(GitChangeType.ADD, "test.txt"));
    flushAWT();
    SwingUtilities.invokeLater(() -> autoPushBtn.setSelected(true));
    flushAWT();
    assertTrue(autoPushBtn.isSelected());
    SwingUtilities.invokeLater(() -> {
        stagingPanel.getCommitPanel().getCommitMessageArea().setText("Another commit message");
        stagingPanel.getCommitPanel().getCommitButton().doClick();
    });
    waitForScheluerBetter();
    sleep(500);
    flushAWT();
    assertEquals(0, GitAccess.getInstance().getPushesAhead());
}
Also used : Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JideToggleButton(com.jidesoft.swing.JideToggleButton) File(java.io.File)

Aggregations

JideToggleButton (com.jidesoft.swing.JideToggleButton)7 FileStatus (com.oxygenxml.git.service.entities.FileStatus)5 File (java.io.File)5 Repository (org.eclipse.jgit.lib.Repository)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 DiffEntry (org.eclipse.jgit.diff.DiffEntry)2 Test (org.junit.Test)2 PluginWorkspace (ro.sync.exml.workspace.api.PluginWorkspace)2 StandalonePluginWorkspace (ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace)2 RepoNotInitializedException (com.oxygenxml.git.service.RepoNotInitializedException)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1