Search in sources :

Example 1 with GitChangeType

use of com.oxygenxml.git.service.entities.GitChangeType in project oxygen-git-client-addon by oxygenxml.

the class StagingResourcesTableCellRenderer method getTableCellRendererComponent.

/**
 * @see javax.swing.table.TableCellRenderer.getTableCellRendererComponent(JTable, Object, boolean, boolean, int, int)
 */
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    Icon icon = null;
    String tooltipText = null;
    String labelText = "";
    JLabel tableCellRendererComponent = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    String location = "";
    if (value instanceof GitChangeType) {
        RenderingInfo renderingInfo = RendererUtil.getChangeRenderingInfo((GitChangeType) value);
        setBorder(BorderFactory.createCompoundBorder(getBorder(), PADDING));
        if (renderingInfo != null) {
            icon = renderingInfo.getIcon();
            tooltipText = renderingInfo.getTooltip();
        }
    } else if (value instanceof FileStatus) {
        location = ((FileStatus) value).getFileLocation();
        setBorder(BorderFactory.createCompoundBorder(getBorder(), PADDING));
        FontMetrics metrics = getFontMetrics(getFont());
        labelText = FileUtil.truncateText(location, metrics, table.getWidth() - table.getColumnModel().getColumn(0).getWidth());
        String description = ((FileStatus) value).getDescription();
        if (description != null) {
            tooltipText = description;
        } else {
            tooltipText = location;
            String fileName = tooltipText.substring(tooltipText.lastIndexOf('/') + 1);
            if (!fileName.equals(tooltipText)) {
                tooltipText = tooltipText.replace("/" + fileName, "");
                tooltipText = fileName + " - " + tooltipText;
            }
        }
    }
    if (isSelected) {
        tableCellRendererComponent.setForeground(table.getSelectionForeground());
    } else {
        updateForegroundText(tableCellRendererComponent);
    }
    tableCellRendererComponent.setIcon(icon);
    tableCellRendererComponent.setToolTipText(tooltipText);
    tableCellRendererComponent.setText(labelText);
    // Active/inactive table selection
    if (table.isRowSelected(row)) {
        if (table.hasFocus()) {
            tableCellRendererComponent.setBackground(table.getSelectionBackground());
        } else if (!contextMenuShowing.getAsBoolean()) {
            Color defaultColor = table.getSelectionBackground();
            tableCellRendererComponent.setBackground(RendererUtil.getInactiveSelectionColor(table, defaultColor));
        }
    } else {
        tableCellRendererComponent.setBackground(table.getBackground());
    }
    return tableCellRendererComponent;
}
Also used : RenderingInfo(com.oxygenxml.git.view.util.RenderingInfo) FileStatus(com.oxygenxml.git.service.entities.FileStatus) FontMetrics(java.awt.FontMetrics) Color(java.awt.Color) GitChangeType(com.oxygenxml.git.service.entities.GitChangeType) JLabel(javax.swing.JLabel) Icon(javax.swing.Icon)

Example 2 with GitChangeType

use of com.oxygenxml.git.service.entities.GitChangeType in project oxygen-git-client-addon by oxygenxml.

the class HistoryViewContextualMenuPresenter method getFileContextualActions.

/**
 * Contributes the contextual actions for the given file and commit.
 *
 * @param fileStatus            The file.
 * @param commitCharacteristics Commit information.
 * @param addFileName           <code>true</code> to add the name of the file to the action's name.
 *
 * @return A list with actions that can be executed over the given file. Never null.
 */
public List<Action> getFileContextualActions(FileStatus fileStatus, CommitCharacteristics commitCharacteristics, boolean addFileName) {
    List<Action> actions = new LinkedList<>();
    String fileStatusLocation = fileStatus.getFileLocation();
    GitChangeType fileStatusChangeType = fileStatus.getChangeType();
    String currentCommitID = commitCharacteristics.getCommitId();
    if (fileStatusChangeType != GitChangeType.REMOVED && fileStatusChangeType != GitChangeType.MISSING) {
        if (!GitAccess.UNCOMMITED_CHANGES.getCommitId().equals(currentCommitID)) {
            createCompareActionsForCommit(actions, commitCharacteristics, addFileName, fileStatus);
        } else if (fileStatusChangeType != GitChangeType.ADD && fileStatusChangeType != GitChangeType.UNTRACKED) {
            // Uncommitted changes. Compare between local and HEAD.
            actions.add(new AbstractAction(TRANSLATOR.getTranslation(Tags.OPEN_IN_COMPARE)) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    DiffPresenter.showDiff(fileStatus, gitCtrl);
                }
            });
        }
    }
    if (!actions.isEmpty()) {
        actions.add(null);
    }
    actions.add(createOpenFileAction(currentCommitID, fileStatus, addFileName));
    if (!GitAccess.UNCOMMITED_CHANGES.getCommitId().equals(currentCommitID) && fileStatusChangeType != GitChangeType.REMOVED) {
        actions.add(createOpenWorkingCopyFileAction(fileStatus, currentCommitID, addFileName));
    }
    if (fileStatusChangeType != GitChangeType.REMOVED && fileStatusChangeType != GitChangeType.UNTRACKED && !GitAccess.UNCOMMITED_CHANGES.getCommitId().equals(currentCommitID) && existsLocalFile(fileStatusLocation)) {
        actions.add(null);
        actions.add(createCheckoutFileAction(currentCommitID, fileStatus, addFileName));
    }
    return actions;
}
Also used : CreateBranchFromCommitAction(com.oxygenxml.git.view.history.actions.CreateBranchFromCommitAction) Action(javax.swing.Action) ResetBranchToCommitAction(com.oxygenxml.git.view.history.actions.ResetBranchToCommitAction) RevertCommitAction(com.oxygenxml.git.view.history.actions.RevertCommitAction) AbstractAction(javax.swing.AbstractAction) CreateTagAction(com.oxygenxml.git.view.history.actions.CreateTagAction) CheckoutCommitAction(com.oxygenxml.git.view.history.actions.CheckoutCommitAction) ActionEvent(java.awt.event.ActionEvent) GitChangeType(com.oxygenxml.git.service.entities.GitChangeType) AbstractAction(javax.swing.AbstractAction) LinkedList(java.util.LinkedList)

Example 3 with GitChangeType

use of com.oxygenxml.git.service.entities.GitChangeType in project oxygen-git-client-addon by oxygenxml.

the class ChangesTreeCellRenderer method getTreeCellRendererComponent.

/**
 * @see javax.swing.tree.DefaultTreeCellRenderer.getTreeCellRendererComponent(JTree, Object, boolean, boolean, boolean, int, boolean)
 */
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    Icon icon = Icons.getIcon(Icons.FOLDER_TREE_ICON);
    String toolTip = null;
    StagingResourcesTreeModel model = (StagingResourcesTreeModel) tree.getModel();
    TreePath treePath = tree.getPathForRow(row);
    if (treePath != null) {
        String path = TreeUtil.getStringPath(treePath);
        if (!"".equals(path) && model.isLeaf(TreeUtil.getTreeNodeFromString(model, path))) {
            FileStatus file = model.getFileByPath(path);
            if (file != null) {
                GitChangeType changeType = file.getChangeType();
                RenderingInfo renderingInfo = RendererUtil.getChangeRenderingInfo(changeType);
                if (renderingInfo != null) {
                    icon = renderingInfo.getIcon();
                    toolTip = renderingInfo.getTooltip();
                }
                if (file.getDescription() != null) {
                    toolTip = file.getDescription();
                }
            } else {
                label = null;
            }
        }
    }
    if (label != null) {
        label.setIcon(icon);
        label.setToolTipText(toolTip);
        if (sel) {
            setBackgroundSelectionColor(tree);
        }
    }
    return label;
}
Also used : RenderingInfo(com.oxygenxml.git.view.util.RenderingInfo) FileStatus(com.oxygenxml.git.service.entities.FileStatus) TreePath(javax.swing.tree.TreePath) GitChangeType(com.oxygenxml.git.service.entities.GitChangeType) JLabel(javax.swing.JLabel) Icon(javax.swing.Icon)

Example 4 with GitChangeType

use of com.oxygenxml.git.service.entities.GitChangeType in project oxygen-git-client-addon by oxygenxml.

the class GitResourceContextualMenu method populateMenu.

/**
 * Populates the contextual menu for the selected files.
 *
 * @param selResProvider   Provides the resources that will be processed by the menu's actions.
 * @param forStagedRes     <code>true</code> if the contextual menu is created for staged files.
 */
private void populateMenu(final SelectedResourcesProvider selResProvider, final boolean forStagedRes) {
    if (selResProvider.getAllSelectedResources().isEmpty() && !RepoUtil.isUnfinishedConflictState(repoState)) {
        return;
    }
    final List<FileStatus> allSelectedResources = selResProvider.getAllSelectedResources();
    final List<FileStatus> selectedLeaves = selResProvider.getOnlySelectedLeaves();
    createAllActions(allSelectedResources, selectedLeaves, selResProvider, forStagedRes);
    // Resolve Conflict
    JMenu resolveConflict = new JMenu();
    resolveConflict.setText(TRANSLATOR.getTranslation(Tags.RESOLVE_CONFLICT));
    resolveConflict.add(showDiffAction);
    resolveConflict.addSeparator();
    resolveConflict.add(resolveUsingMineAction);
    resolveConflict.add(resolveUsingTheirsAction);
    resolveConflict.add(markResolvedAction);
    resolveConflict.addSeparator();
    resolveConflict.add(restartMergeAction);
    // Populate contextual menu
    this.add(showDiffAction);
    this.add(openAction);
    addSeparator();
    this.add(stageUnstageAction);
    this.add(resolveConflict);
    this.add(discardAction);
    if (!forStagedRes) {
        addSeparator();
        historyAction.setEnabled(FileUtil.shouldEnableBlameAndHistory(allSelectedResources));
        this.add(historyAction);
        blameAction.setEnabled(FileUtil.shouldEnableBlameAndHistory(allSelectedResources));
        this.add(blameAction);
    }
    boolean allSelResHaveSameChangeType = true;
    boolean selectionContainsConflicts = false;
    boolean selectionContainsDeletions = false;
    if (!allSelectedResources.isEmpty()) {
        GitChangeType firstChangeType = allSelectedResources.get(0).getChangeType();
        for (FileStatus file : allSelectedResources) {
            GitChangeType changeType = file.getChangeType();
            allSelResHaveSameChangeType = changeType == firstChangeType && allSelResHaveSameChangeType;
            switch(changeType) {
                case CONFLICT:
                    selectionContainsConflicts = true;
                    break;
                case MISSING:
                // jump to the next case
                case REMOVED:
                    selectionContainsDeletions = true;
                    break;
                default:
                    break;
            }
        }
    }
    // Enable/disable the actions
    showDiffAction.setEnabled(selectedLeaves.size() == 1);
    openAction.setEnabled(!selectionContainsDeletions && !allSelectedResources.isEmpty());
    stageUnstageAction.setEnabled(!selectionContainsConflicts && !allSelectedResources.isEmpty());
    resolveConflict.setEnabled(RepoUtil.isUnfinishedConflictState(repoState) || selectionContainsConflicts);
    resolveUsingMineAction.setEnabled(selectionContainsConflicts && allSelResHaveSameChangeType && !allSelectedResources.isEmpty());
    resolveUsingTheirsAction.setEnabled(selectionContainsConflicts && allSelResHaveSameChangeType && !allSelectedResources.isEmpty());
    markResolvedAction.setEnabled(selectionContainsConflicts && allSelResHaveSameChangeType && !allSelectedResources.isEmpty());
    restartMergeAction.setEnabled(RepoUtil.isRepoMergingOrRebasing(repoState));
    discardAction.setEnabled(!selectionContainsConflicts && !allSelectedResources.isEmpty());
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) GitChangeType(com.oxygenxml.git.service.entities.GitChangeType) JMenu(javax.swing.JMenu)

Example 5 with GitChangeType

use of com.oxygenxml.git.service.entities.GitChangeType in project oxygen-git-client-addon by oxygenxml.

the class DiffPresenter method diffViewForAddedAndUntracked.

/**
 * Diff for added/untracked resources.
 *
 * @param fileStatus File to compare.
 */
private static void diffViewForAddedAndUntracked(FileStatus fileStatus) {
    URL url = null;
    try {
        GitChangeType changeType = fileStatus.getChangeType();
        if (changeType == GitChangeType.ADD) {
            url = GitRevisionURLHandler.encodeURL(VersionIdentifier.INDEX_OR_LAST_COMMIT, fileStatus.getFileLocation());
        } else {
            url = FileUtil.getFileURL(fileStatus.getFileLocation());
        }
    } catch (MalformedURLException | NoRepositorySelected e) {
        // Shouldn't rreally happen
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(e.getMessage(), e);
        }
    }
    showDiffFrame(url, null, null, fileStatus.getFileLocation());
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) MalformedURLException(java.net.MalformedURLException) GitChangeType(com.oxygenxml.git.service.entities.GitChangeType) URL(java.net.URL)

Aggregations

GitChangeType (com.oxygenxml.git.service.entities.GitChangeType)6 FileStatus (com.oxygenxml.git.service.entities.FileStatus)3 RenderingInfo (com.oxygenxml.git.view.util.RenderingInfo)2 Icon (javax.swing.Icon)2 JLabel (javax.swing.JLabel)2 NoRepositorySelected (com.oxygenxml.git.service.NoRepositorySelected)1 CheckoutCommitAction (com.oxygenxml.git.view.history.actions.CheckoutCommitAction)1 CreateBranchFromCommitAction (com.oxygenxml.git.view.history.actions.CreateBranchFromCommitAction)1 CreateTagAction (com.oxygenxml.git.view.history.actions.CreateTagAction)1 ResetBranchToCommitAction (com.oxygenxml.git.view.history.actions.ResetBranchToCommitAction)1 RevertCommitAction (com.oxygenxml.git.view.history.actions.RevertCommitAction)1 Color (java.awt.Color)1 FontMetrics (java.awt.FontMetrics)1 ActionEvent (java.awt.event.ActionEvent)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 LinkedList (java.util.LinkedList)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 JMenu (javax.swing.JMenu)1