use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class ListStashesDialog method createAffectedFilesTable.
/**
* Creates table for affected files by stash.
*
* @return The created table.
*/
private Table createAffectedFilesTable() {
affectedStashFilesTableModel = new FilesTableModel();
final Comparator<FileStatus> comparator = (f1, f2) -> {
int comparationResult = f1.getChangeType().compareTo(f2.getChangeType());
if (comparationResult == 0) {
// Same change type. Third level sort.
comparationResult = f1.getFileLocation().compareTo(f2.getFileLocation());
}
return comparationResult;
};
affectedStashFilesTableModel.setComparator(comparator);
Table filesTable = new Table(affectedStashFilesTableModel) {
@Override
public JToolTip createToolTip() {
return UIUtil.createMultilineTooltip(this).orElseGet(super::createToolTip);
}
};
filesTable.setFillsViewportHeight(true);
filesTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent evt) {
int selectedRow = stashesTable.getSelectedRow();
if (selectedRow >= 0 && !evt.isPopupTrigger() && evt.getClickCount() == 2) {
compareWithWorkingCopyAction.actionPerformed(null);
}
}
});
JPopupMenu contextualActions = new JPopupMenu();
contextualActions.add(compareWithWorkingCopyAction);
filesTable.setComponentPopupMenu(contextualActions);
filesTable.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER && filesTable.getSelectedRow() >= 0 && filesTable.getSelectedRow() < filesTable.getRowCount()) {
compareWithWorkingCopyAction.actionPerformed(null);
}
}
});
addClickRightSelection(filesTable, contextualActions);
filesTable.getColumnModel().setColumnMargin(0);
filesTable.setTableHeader(null);
filesTable.setShowGrid(false);
Icon icon = Icons.getIcon(Icons.GIT_ADD_ICON);
int iconWidth = icon.getIconWidth();
int colWidth = iconWidth + RESOURCE_TABLE_ICON_COLUMN_EXTRA_WIDTH;
TableColumn statusCol = filesTable.getColumnModel().getColumn(StagingResourcesTableModel.FILE_STATUS_COLUMN);
statusCol.setMinWidth(colWidth);
statusCol.setPreferredWidth(colWidth);
statusCol.setMaxWidth(colWidth);
filesTable.setDefaultRenderer(Object.class, new StagingResourcesTableCellRenderer(() -> false));
return filesTable;
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class HistoryPanel method showResourcesContextualMenu.
/**
* Show the contextual menu on the resources changed on a revision.
*
* @param affectedFilesTable The table with the files from a committed on a
* revision.
* @param point The point where to show the contextual menu.
*/
protected void showResourcesContextualMenu(JTable affectedFilesTable, Point point) {
int rowAtPoint = affectedFilesTable.rowAtPoint(point);
if (rowAtPoint != -1) {
updateTableSelection(affectedFilesTable, rowAtPoint);
HistoryTableAffectedFilesModel model = (HistoryTableAffectedFilesModel) affectedFilesTable.getModel();
int convertedSelectedRow = affectedFilesTable.convertRowIndexToModel(rowAtPoint);
FileStatus file = model.getFileStatus(convertedSelectedRow);
HistoryCommitTableModel historyTableModel = (HistoryCommitTableModel) historyTable.getModel();
CommitCharacteristics commitCharacteristics = historyTableModel.getAllCommits().get(historyTable.getSelectedRow());
JPopupMenu jPopupMenu = new JPopupMenu();
contextualMenuPresenter.populateContextActionsForFile(jPopupMenu, file, commitCharacteristics, false);
jPopupMenu.show(affectedFilesTable, point.x, point.y);
}
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class HistoryPanel method historyDoubleClickAction.
/**
* Opens the first action in the contextual menu when an element inside the
* history table is double clicked.
*
* @param rowAtPoint Position of the element in the history table.
*/
private void historyDoubleClickAction(int rowAtPoint) {
HistoryCommitTableModel historyTableModel = (HistoryCommitTableModel) historyTable.getModel();
int convertedSelectedRow = historyTable.convertRowIndexToModel(rowAtPoint);
CommitCharacteristics commitCharacteristics = historyTableModel.getAllCommits().get(convertedSelectedRow);
try {
Optional<FileStatus> optionalFileStatus = contextualMenuPresenter.getFileStatus(activeFilePath, commitCharacteristics);
if (optionalFileStatus.isPresent()) {
FileStatus fileStatus = optionalFileStatus.get();
List<Action> contextualActions = contextualMenuPresenter.getFileContextualActions(fileStatus, commitCharacteristics, false);
if (!contextualActions.isEmpty()) {
contextualActions.get(0).actionPerformed(null);
}
}
} catch (IOException | GitAPIException e1) {
PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(e1.getMessage());
LOGGER.error(e1.getMessage(), e1);
}
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class HistoryViewContextualMenuPresenter method getFileURL.
/**
* Builds an URL that identifies a file at a specific revision.
*
* @param revisionID Revision ID.
* @param fileStatus FIle info.
*
* @return The URL, if one was built.
*
* @throws NoRepositorySelected No repository is loaded.
* @throws IOException Problems identifying the revision.
*/
private Optional<URL> getFileURL(String revisionID, FileStatus fileStatus) throws NoRepositorySelected, IOException {
URL fileURL = null;
String fileStatusLocation = fileStatus.getFileLocation();
if (fileStatus.getChangeType() == GitChangeType.REMOVED) {
Repository repository = GitAccess.getInstance().getRepository();
RevCommit[] parentsRevCommits = RevCommitUtil.getParents(repository, revisionID);
// If it's a merge, we look for the one parent with the actual file in it.
Optional<RevCommit> previousVersionCommit = Arrays.stream(parentsRevCommits).filter(revCommit -> {
try {
return RevCommitUtil.getObjectID(repository, revCommit.getId().getName(), fileStatusLocation) != null;
} catch (IOException e1) {
// Unable to find a parent with the given path.
PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage("Unable to open file because of " + e1.getMessage());
}
return false;
}).findFirst();
if (previousVersionCommit.isPresent()) {
fileURL = GitRevisionURLHandler.encodeURL(previousVersionCommit.get().getId().getName(), fileStatusLocation);
}
} else if (fileStatus.getChangeType() == GitChangeType.MISSING) {
fileURL = GitRevisionURLHandler.encodeURL(VersionIdentifier.INDEX_OR_LAST_COMMIT, fileStatusLocation);
} else if (!GitAccess.UNCOMMITED_CHANGES.getCommitId().equals(revisionID)) {
fileURL = GitRevisionURLHandler.encodeURL(revisionID, fileStatusLocation);
} else {
fileURL = FileUtil.getFileURL(fileStatusLocation);
}
return Optional.ofNullable(fileURL);
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class HistoryViewContextualMenuPresenter method populateActions4SingleSelection.
/**
* Contributes the contextual actions for the given file, at the given revision/commit.
*
* @param jPopupMenu Contextual menu in which to put the actions.
* @param filePath File path.
* @param commitCharacteristics Revision/commit data.
*
* @throws IOException If it fails.
* @throws GitAPIException If it fails.
*/
private void populateActions4SingleSelection(JPopupMenu jPopupMenu, String filePath, CommitCharacteristics commitCharacteristics) throws IOException, GitAPIException {
if (filePath != null) {
Optional<FileStatus> fileStatusOptional = getFileStatus(filePath, commitCharacteristics);
fileStatusOptional.ifPresent(fileStatus -> populateContextActionsForFile(jPopupMenu, fileStatus, commitCharacteristics, true));
}
if (filePath != null) {
jPopupMenu.addSeparator();
}
String commitId = commitCharacteristics.getCommitId();
if (!GitAccess.UNCOMMITED_CHANGES.getCommitId().equals(commitId)) {
jPopupMenu.add(new CreateBranchFromCommitAction(commitId));
jPopupMenu.add(new CreateTagAction(commitId));
jPopupMenu.add(new CheckoutCommitAction(commitCharacteristics.getPlotCommit()));
jPopupMenu.addSeparator();
jPopupMenu.add(new RevertCommitAction(commitCharacteristics));
jPopupMenu.add(new ResetBranchToCommitAction(commitCharacteristics));
}
}
Aggregations