use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class ChangesPanel method setResourcesViewMode.
/**
* Set the current view mode for the resources: tree or table.
*
* @param viewMode The new view mode.
*/
void setResourcesViewMode(ResourcesViewMode viewMode) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Switch to " + viewMode);
}
this.currentViewMode = viewMode;
if (viewMode == ResourcesViewMode.TREE_VIEW) {
StagingResourcesTableModel modelTable = (StagingResourcesTableModel) filesTable.getModel();
List<FileStatus> filesStatuses = modelTable.getFilesStatuses();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Table model " + filesStatuses);
}
// Create the tree with the new model
tree.setModel(new StagingResourcesTreeModel(gitController, GitAccess.getInstance().getWorkingCopyName(), forStagedResources, filesStatuses));
restoreSelectedPathsFromTableToTree();
// Activate the tree view.
scrollPane.setViewportView(tree);
} else {
// Get the list of files from the tree model and update the table.
StagingResourcesTreeModel treeModel = (StagingResourcesTreeModel) tree.getModel();
List<FileStatus> filesStatuses = treeModel.getFilesStatuses();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Tree model " + filesStatuses);
}
StagingResourcesTableModel tableModel = (StagingResourcesTableModel) filesTable.getModel();
tableModel.setFilesStatus(filesStatuses);
List<TreePath> commonAncestors = TreeUtil.getTreeCommonAncestors(tree.getSelectionPaths());
List<Integer> tableRowsToSelect = new ArrayList<>();
for (TreePath treePath : commonAncestors) {
String path = TreeUtil.getStringPath(treePath);
tableRowsToSelect.addAll(tableModel.getRows(path));
}
filesTable.clearSelection();
for (Integer i : tableRowsToSelect) {
filesTable.addRowSelectionInterval(i, i);
}
// Activate the table view.
scrollPane.setViewportView(filesTable);
}
updateChangeViewButton();
if (forStagedResources) {
OptionsManager.getInstance().saveStagedResViewMode(viewMode);
} else {
OptionsManager.getInstance().saveUnstagedResViewMode(viewMode);
}
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class ChangesPanel method openFileInCompareEditor.
/**
* Open an instance of diff presenter and compares current file with the last commit.
*
* @param row Selection index of file in the current table.
*/
private void openFileInCompareEditor(int row) {
StagingResourcesTableModel model = (StagingResourcesTableModel) filesTable.getModel();
int convertedRow = filesTable.convertRowIndexToModel(row);
FileStatus file = model.getUnstageFile(convertedRow);
DiffPresenter.showDiff(file, gitController);
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class ChangesPanel method addTreeMouseListener.
/**
* Adds a mouse listener to the tree: When the user right clicks on a node, a
* contextual menu will pop. Also when the user double clicks on a leaf node
* an action will occur depending on it's file status. If the status is MODIFY
* the open in compare editor will be executed, if the status is Add the file
* will be opened in the Oxygen
*/
private void addTreeMouseListener() {
tree.getSelectionModel().addTreeSelectionListener(e -> toggleSelectedButton());
tree.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
// For MacOS the popup trigger comes on mouse pressed.
handleContextualMenuEvent(e);
}
@Override
public void mouseReleased(MouseEvent e) {
// Switching between Staged and UnStaged with right click introduced some paint artifacts.
tree.requestFocus();
tree.repaint();
// Maybe the event was a (not pop-up trigger) double-click
showDiff(e);
// Or maybe it was a right click
handleContextualMenuEvent(e);
}
/**
* Shows the contextual menu, if the mouse event is a pop-up trigger.
*
* @param e Mouse event.
*/
private void handleContextualMenuEvent(MouseEvent e) {
if (e.isPopupTrigger() && e.getClickCount() == 1) {
// ============= Right click event ================
// First, check the node under the mouse.
TreePath treePath = tree.getPathForLocation(e.getX(), e.getY());
if (treePath != null) {
boolean treeInSelection = false;
TreePath[] paths = tree.getSelectionPaths();
// A JTree only updates selection for a left button. Also do it for a right click.
if (paths != null) {
for (TreePath path : paths) {
if (treePath.equals(path)) {
treeInSelection = true;
break;
}
}
}
if (!treeInSelection) {
tree.setSelectionPath(treePath);
}
} else {
// A click outside the tree. Go with a selected path.
treePath = tree.getSelectionPath();
}
if (treePath != null) {
String stringPath = TreeUtil.getStringPath(treePath);
StagingResourcesTreeModel model = (StagingResourcesTreeModel) tree.getModel();
GitTreeNode node = TreeUtil.getTreeNodeFromString(model, stringPath);
if (node != null && (!node.isRoot() || node.children().hasMoreElements() || isMergingResolved())) {
showContextualMenuForTree(e.getX(), e.getY(), model);
}
}
}
}
/**
* Shows DIFF for a double click mouse event.
*
* @param e Mouse event.
*/
private void showDiff(MouseEvent e) {
if (!e.isPopupTrigger() && e.getClickCount() == 2) {
// ============= Double click event ==============
TreePath treePath = tree.getPathForLocation(e.getX(), e.getY());
if (treePath != null) {
String stringPath = TreeUtil.getStringPath(treePath);
StagingResourcesTreeModel model = (StagingResourcesTreeModel) tree.getModel();
GitTreeNode node = TreeUtil.getTreeNodeFromString(model, stringPath);
if (model.isLeaf(node) && !model.getRoot().equals(node)) {
FileStatus file = model.getFileByPath(stringPath);
DiffPresenter.showDiff(file, gitController);
}
}
}
}
});
}
use of com.oxygenxml.git.service.entities.FileStatus 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.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class StagingResourcesTreeModel method insertNodes.
/**
* Insert nodes to the tree based on the given files
*
* @param fileToBeUpdated
* - the files on which the nodes will be created
*/
private void insertNodes(List<FileStatus> fileToBeUpdated) {
for (FileStatus fileStatus : fileToBeUpdated) {
TreeUtil.buildTreeFromString(this, fileStatus.getFileLocation());
}
filesStatuses.addAll(fileToBeUpdated);
TreeUtil.sortGitTree(this);
}
Aggregations