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;
}
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;
}
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;
}
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());
}
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());
}
Aggregations