Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.LinkedList;

import org.apache.poi.ss.util.CellRangeAddress;
import org.jsoup.Jsoup;
import org.jsoup.safety.Safelist;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -42,6 +44,23 @@

private int contextMenuHeaderIndex = -1;

/**
* Enum for spreadsheet action types.
*/
enum ActionType {
CELL(0), ROW(1), COLUMN(2);

private final int value;

ActionType(int value) {
this.value = value;
}

public int getValue() {
return value;
}
}

/**
* Constructs a new ContextMenuManager and ties it to the given Spreadsheet.
*
Expand Down Expand Up @@ -216,19 +235,11 @@
protected ArrayList<SpreadsheetActionDetails> createActionsListForSelection() {
ArrayList<SpreadsheetActionDetails> actions = new ArrayList<SpreadsheetActionDetails>();
for (Handler handler : actionHandlers) {
Action[] actions2 = handler.getActions(spreadsheet
Action[] handlerActions = handler.getActions(spreadsheet
.getCellSelectionManager().getLatestSelectionEvent(),
spreadsheet);
if (actions2 != null) {
for (Action action : actions2) {
String key = actionMapper.key(action);
SpreadsheetActionDetails spreadsheetActionDetails = new SpreadsheetActionDetails();
spreadsheetActionDetails.caption = action.getCaption();
spreadsheetActionDetails.key = key;
spreadsheetActionDetails.type = 0;
actions.add(spreadsheetActionDetails);
}
}
actions.addAll(
createActionDetailsList(handlerActions, ActionType.CELL));
}
return actions;
}
Expand All @@ -246,14 +257,9 @@
final CellRangeAddress column = new CellRangeAddress(-1, -1,
columnIndex - 1, columnIndex - 1);
for (Handler handler : actionHandlers) {
for (Action action : handler.getActions(column, spreadsheet)) {
String key = actionMapper.key(action);
SpreadsheetActionDetails spreadsheetActionDetails = new SpreadsheetActionDetails();
spreadsheetActionDetails.caption = action.getCaption();
spreadsheetActionDetails.key = key;
spreadsheetActionDetails.type = 2;
actions.add(spreadsheetActionDetails);
}
Action[] handlerActions = handler.getActions(column, spreadsheet);
actions.addAll(
createActionDetailsList(handlerActions, ActionType.COLUMN));
}
return actions;
}
Expand All @@ -271,16 +277,40 @@
final CellRangeAddress row = new CellRangeAddress(rowIndex - 1,
rowIndex - 1, -1, -1);
for (Handler handler : actionHandlers) {
for (Action action : handler.getActions(row, spreadsheet)) {
Action[] handlerActions = handler.getActions(row, spreadsheet);
actions.addAll(
createActionDetailsList(handlerActions, ActionType.ROW));
}
return actions;
}

/**
* Helper method to create SpreadsheetActionDetails from actions.
*
* @param actions
* Array of actions to convert
* @param actionType
* Type of the action (cell, row, or column)
* @return List of SpreadsheetActionDetails
*/
private ArrayList<SpreadsheetActionDetails> createActionDetailsList(
Action[] actions, ActionType actionType) {
ArrayList<SpreadsheetActionDetails> actionDetailsList = new ArrayList<SpreadsheetActionDetails>();

Check warning on line 298 in vaadin-spreadsheet-flow-parent/vaadin-spreadsheet-flow/src/main/java/com/vaadin/flow/component/spreadsheet/ContextMenuManager.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the type specification in this constructor call with the diamond operator ("<>").

See more on https://sonarcloud.io/project/issues?id=vaadin_flow-components&issues=AZro3Bs7IyyH1yIdVlj-&open=AZro3Bs7IyyH1yIdVlj-&pullRequest=8326
if (actions != null) {
for (Action action : actions) {
String key = actionMapper.key(action);
SpreadsheetActionDetails spreadsheetActionDetails = new SpreadsheetActionDetails();
spreadsheetActionDetails.caption = action.getCaption();
String caption = action.getCaption();
if (caption == null) {
caption = "";
}
spreadsheetActionDetails.caption = Jsoup.clean(caption,
Safelist.relaxed());
spreadsheetActionDetails.key = key;
spreadsheetActionDetails.type = 1;
actions.add(spreadsheetActionDetails);
spreadsheetActionDetails.type = actionType.getValue();
actionDetailsList.add(spreadsheetActionDetails);
}
}
return actions;
return actionDetailsList;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
public class SpreadsheetActionDetails implements Serializable {
public String caption;
public String key;
/** 0 = cell, 1 = row, 2 = column TODO replace with enum type */
/**
* 0 = cell, 1 = row, 2 = column - kept as int for client-server
* compatibility
*/
public int type;
}
Loading