use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class RevCommitUtil method addUntrackedFiles.
/**
* Add the untracked files to files list.
*
* @param changedFiles The container to add files.
* @param repository The Git repository.
* @param revWalk The RevWalk.
* @param commit The stash commit.
*
* @throws IOException
*/
private static void addUntrackedFiles(List<FileStatus> changedFiles, Repository repository, RevWalk revWalk, RevCommit commit) throws IOException {
RevCommit oldC;
oldC = revWalk.parseCommit(commit.getParent(PARENT_COMMIT_UNTRACKED));
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(commit.getTree());
treeWalk.setRecursive(false);
treeWalk.setFilter(null);
treeWalk.reset(oldC.getTree().getId());
while (treeWalk.next()) {
if (treeWalk.isSubtree()) {
treeWalk.enterSubtree();
} else {
String path = treeWalk.getPathString();
changedFiles.add(new FileStatus(GitChangeType.UNTRACKED, path));
}
}
}
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class GitStatusCommand method getStagedFiles.
/**
* Checks which files from the given subset are in the Index and returns their
* state.
*
* @param status The current status.
*
* @return - a set containing the subset of files present in the INDEX.
*/
private List<FileStatus> getStagedFiles(Status status) {
List<FileStatus> stagedFiles = new ArrayList<>();
Set<String> submodules = getSubmoduleAccess().getSubmodules();
for (String fileName : status.getChanged()) {
// File from INDEX, modified from HEAD
if (submodules.contains(fileName)) {
stagedFiles.add(new FileStatus(GitChangeType.SUBMODULE, fileName));
} else {
stagedFiles.add(new FileStatus(GitChangeType.CHANGED, fileName));
}
}
for (String fileName : status.getAdded()) {
// Newly created files added in the INDEX
if (submodules.contains(fileName)) {
stagedFiles.add(new FileStatus(GitChangeType.SUBMODULE, fileName));
} else {
stagedFiles.add(new FileStatus(GitChangeType.ADD, fileName));
}
}
for (String fileName : status.getRemoved()) {
// A delete added in the INDEX, file is present in HEAD.
if (submodules.contains(fileName)) {
stagedFiles.add(new FileStatus(GitChangeType.SUBMODULE, fileName));
} else {
stagedFiles.add(new FileStatus(GitChangeType.REMOVED, fileName));
}
}
return stagedFiles;
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class GitControllerBase method discard.
/**
* Discard files.
*
* @param filesStatuses The resources to discard.
*/
private void discard(List<FileStatus> filesStatuses) {
gitAccess.resetAll(filesStatuses);
List<String> paths = new LinkedList<>();
for (FileStatus file : filesStatuses) {
if (file.getChangeType() != GitChangeType.SUBMODULE) {
paths.add(file.getFileLocation());
}
}
gitAccess.restoreLastCommitFile(paths);
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class ChangesPanel method showContextualMenuForFlatView.
/**
* Show contextual menu for flat view.
*
* @param x The X coordinate where to show the menu.
* @param y The Y coordinate where to show the menu.
* @param selectedRows The selected rows.
*/
private void showContextualMenuForFlatView(int x, int y, int[] selectedRows) {
final List<FileStatus> files = new ArrayList<>();
for (int selectedRow : selectedRows) {
int convertedSelectedRow = filesTable.convertRowIndexToModel(selectedRow);
StagingResourcesTableModel model = (StagingResourcesTableModel) filesTable.getModel();
FileStatus file = new FileStatus(model.getUnstageFile(convertedSelectedRow));
files.add(file);
}
GitResourceContextualMenu contextualMenu = new GitResourceContextualMenu(new SelectedResourcesProvider() {
@Override
public List<FileStatus> getOnlySelectedLeaves() {
// All resources are "leaves" in the table view.
return getAllSelectedResources();
}
@Override
public List<FileStatus> getAllSelectedResources() {
return files;
}
}, gitController, historyController, forStagedResources, RepoUtil.getRepoState());
contextualMenu.addPopupMenuListener(popupMenuListener);
contextualMenu.show(filesTable, x, y);
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class ChangesPanel method createTopPanelToolbarButtons.
/**
* Create the buttons for the toolbar in the top panel.
*/
private void createTopPanelToolbarButtons() {
// Change selected
String changeSelectedTranslationTag = forStagedResources ? Tags.UNSTAGE_SELECTED_BUTTON_TEXT : Tags.STAGE_SELECTED_BUTTON_TEXT;
String changeSelectedIconTag = forStagedResources ? Icons.UNSTAGE_SELECTED : Icons.STAGE_SELECTED;
changeSelectedButton = OxygenUIComponentsFactory.createToolbarButton(new AbstractAction(TRANSLATOR.getTranslation(changeSelectedTranslationTag), Icons.getIcon(changeSelectedIconTag)) {
@Override
public void actionPerformed(ActionEvent e) {
List<FileStatus> fileStatuses = new ArrayList<>();
if (currentViewMode == ResourcesViewMode.FLAT_VIEW) {
int[] selectedRows = filesTable.getSelectedRows();
StagingResourcesTableModel fileTableModel = (StagingResourcesTableModel) filesTable.getModel();
for (int i = selectedRows.length - 1; i >= 0; i--) {
int convertedRow = filesTable.convertRowIndexToModel(selectedRows[i]);
FileStatus fileStatus = fileTableModel.getFileStatus(convertedRow);
fileStatuses.add(fileStatus);
}
} else {
List<String> selectedFiles = TreeUtil.getStringComonAncestor(tree);
StagingResourcesTreeModel fileTreeModel = (StagingResourcesTreeModel) tree.getModel();
List<FileStatus> fileStatusesForPaths = fileTreeModel.getFilesByPaths(selectedFiles);
fileStatuses.addAll(fileStatusesForPaths);
}
// "Stage"/"Unstage" actions
AbstractAction stageUnstageAction = new StageUnstageResourceAction(fileStatuses, !forStagedResources, gitController);
stageUnstageAction.actionPerformed(null);
changeSelectedButton.setEnabled(false);
}
}, false);
changeSelectedButton.setEnabled(false);
// Change all
String changeAllTranslationTag = forStagedResources ? Tags.UNSTAGE_ALL_BUTTON_TEXT : Tags.STAGE_ALL_BUTTON_TEXT;
String changeAllIconTag = forStagedResources ? Icons.UNSTAGE_ALL : Icons.STAGE_ALL;
changeAllButton = OxygenUIComponentsFactory.createToolbarButton(new AbstractAction(TRANSLATOR.getTranslation(changeAllTranslationTag), Icons.getIcon(changeAllIconTag)) {
@Override
public void actionPerformed(ActionEvent e) {
if (currentViewMode == ResourcesViewMode.FLAT_VIEW) {
StagingResourcesTableModel fileTableModel = (StagingResourcesTableModel) filesTable.getModel();
fileTableModel.switchAllFilesStageState();
} else {
StagingResourcesTreeModel treeModel = (StagingResourcesTreeModel) tree.getModel();
treeModel.switchAllFilesStageState();
}
}
}, false);
changeAllButton.setEnabled(true);
// Switch view mode
String iconType = currentViewMode == ResourcesViewMode.FLAT_VIEW ? Icons.TREE_VIEW : Icons.LIST_VIEW;
switchViewButton = OxygenUIComponentsFactory.createToolbarButton(new AbstractAction(null, Icons.getIcon(iconType)) {
@Override
public void actionPerformed(ActionEvent e) {
setResourcesViewMode(currentViewMode == ResourcesViewMode.FLAT_VIEW ? ResourcesViewMode.TREE_VIEW : ResourcesViewMode.FLAT_VIEW);
isContextualMenuShowing = false;
}
}, false);
switchViewButton.setToolTipText(TRANSLATOR.getTranslation(Tags.CHANGE_TREE_VIEW_BUTTON_TOOLTIP));
}
Aggregations