Search in sources :

Example 1 with StageUnstageResourceAction

use of com.oxygenxml.git.view.staging.actions.StageUnstageResourceAction 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));
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) StageUnstageResourceAction(com.oxygenxml.git.view.staging.actions.StageUnstageResourceAction) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) AbstractAction(javax.swing.AbstractAction) Point(java.awt.Point)

Example 2 with StageUnstageResourceAction

use of com.oxygenxml.git.view.staging.actions.StageUnstageResourceAction in project oxygen-git-client-addon by oxygenxml.

the class GitResourceContextualMenu method createAllActions.

/**
 * Creates actions for contextual menu.
 *  @param allSelectedResources  A list with all selected resources.
 * @param selectedLeaves         A list of FileStatus with selected leaves.
 * @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 createAllActions(final List<FileStatus> allSelectedResources, final List<FileStatus> selectedLeaves, final SelectedResourcesProvider selResProvider, final boolean forStagedRes) {
    // "Open in compare editor" action
    showDiffAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.OPEN_IN_COMPARE)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            DiffPresenter.showDiff(selectedLeaves.get(0), gitCtrl);
        }
    };
    // "Open" action
    openAction = new OpenAction(selResProvider);
    // "Stage"/"Unstage" actions
    stageUnstageAction = new StageUnstageResourceAction(allSelectedResources, // then the action should be unstage.
    !forStagedRes, gitCtrl);
    // Resolve using "mine"
    resolveUsingMineAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.RESOLVE_USING_MINE)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            gitCtrl.asyncResolveUsingMine(allSelectedResources);
        }
    };
    // Resolve using "theirs"
    resolveUsingTheirsAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.RESOLVE_USING_THEIRS)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            gitCtrl.asyncResolveUsingTheirs(allSelectedResources);
        }
    };
    // "Mark resolved" action
    markResolvedAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.MARK_RESOLVED)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                if (FileUtil.containsConflictMarkers(allSelectedResources, GIT_ACCESS.getWorkingCopy())) {
                    int answer = FileStatusDialog.showWarningMessageWithConfirmation(TRANSLATOR.getTranslation(Tags.MARK_RESOLVED), TRANSLATOR.getTranslation(Tags.CONFLICT_MARKERS_MESSAGE), TRANSLATOR.getTranslation(Tags.RESOLVE_ANYWAY), TRANSLATOR.getTranslation(Tags.CANCEL));
                    if (answer == FileStatusDialog.RESULT_OK) {
                        gitCtrl.asyncAddToIndex(allSelectedResources);
                    }
                } else {
                    gitCtrl.asyncAddToIndex(allSelectedResources);
                }
            } catch (Exception err) {
                LOGGER.error(err.getMessage(), err);
            }
        }
    };
    // "Restart Merge" action
    restartMergeAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.RESTART_MERGE)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            String[] options = new String[] { "   " + TRANSLATOR.getTranslation(Tags.YES) + "   ", "   " + TRANSLATOR.getTranslation(Tags.NO) + "   " };
            int[] optionIds = new int[] { 0, 1 };
            int result = GitResourceContextualMenu.PLUGIN_WS.showConfirmDialog(TRANSLATOR.getTranslation(Tags.RESTART_MERGE), TRANSLATOR.getTranslation(Tags.RESTART_MERGE_CONFIRMATION), options, optionIds);
            if (result == optionIds[0]) {
                GIT_ACCESS.restartMerge();
            }
        }
    };
    // "Discard" action
    discardAction = new DiscardAction(selResProvider, gitCtrl);
    if (!forStagedRes) {
        // Show history
        historyAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.SHOW_HISTORY)) {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!allSelectedResources.isEmpty()) {
                    historyController.showResourceHistory(allSelectedResources.get(0).getFileLocation());
                }
            }
        };
        // "Blame" action
        blameAction = new ShowBlameForUnstagedResourceAction(historyController, selResProvider);
    }
}
Also used : DiscardAction(com.oxygenxml.git.view.staging.actions.DiscardAction) OpenAction(com.oxygenxml.git.view.staging.actions.OpenAction) StageUnstageResourceAction(com.oxygenxml.git.view.staging.actions.StageUnstageResourceAction) ActionEvent(java.awt.event.ActionEvent) ShowBlameForUnstagedResourceAction(com.oxygenxml.git.view.staging.actions.ShowBlameForUnstagedResourceAction) AbstractAction(javax.swing.AbstractAction)

Aggregations

StageUnstageResourceAction (com.oxygenxml.git.view.staging.actions.StageUnstageResourceAction)2 ActionEvent (java.awt.event.ActionEvent)2 AbstractAction (javax.swing.AbstractAction)2 FileStatus (com.oxygenxml.git.service.entities.FileStatus)1 DiscardAction (com.oxygenxml.git.view.staging.actions.DiscardAction)1 OpenAction (com.oxygenxml.git.view.staging.actions.OpenAction)1 ShowBlameForUnstagedResourceAction (com.oxygenxml.git.view.staging.actions.ShowBlameForUnstagedResourceAction)1 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1