Search in sources :

Example 6 with TodoPattern

use of com.intellij.psi.search.TodoPattern in project intellij-community by JetBrains.

the class TodoConfigurable method editSelectedPattern.

private void editSelectedPattern() {
    stopEditing();
    int selectedIndex = myPatternsTable.getSelectedRow();
    if (selectedIndex < 0 || selectedIndex >= myPatternsModel.getRowCount()) {
        return;
    }
    TodoPattern sourcePattern = myPatterns.get(selectedIndex);
    TodoPattern pattern = sourcePattern.clone();
    PatternDialog dialog = new PatternDialog(myPanel, pattern);
    dialog.setTitle(IdeBundle.message("title.edit.todo.pattern"));
    if (!dialog.showAndGet()) {
        return;
    }
    myPatterns.set(selectedIndex, pattern);
    myPatternsModel.fireTableRowsUpdated(selectedIndex, selectedIndex);
    myPatternsTable.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex);
    // Update model with patterns
    for (int i = 0; i < myFilters.size(); i++) {
        TodoFilter filter = myFilters.get(i);
        if (filter.contains(sourcePattern)) {
            filter.removeTodoPattern(sourcePattern);
            filter.addTodoPattern(pattern);
            myFiltersModel.fireTableRowsUpdated(i, i);
        }
    }
}
Also used : TodoFilter(com.intellij.ide.todo.TodoFilter) TodoPattern(com.intellij.psi.search.TodoPattern)

Example 7 with TodoPattern

use of com.intellij.psi.search.TodoPattern in project intellij-community by JetBrains.

the class TodoConfigurable method createComponent.

@Override
public JComponent createComponent() {
    myPatternsTable = new JBTable(myPatternsModel);
    myPatternsTable.getEmptyText().setText(IdeBundle.message("text.todo.no.patterns"));
    TableColumn typeColumn = myPatternsTable.getColumnModel().getColumn(0);
    int width = myPatternsTable.getFontMetrics(myPatternsTable.getFont()).stringWidth(myPatternsTable.getColumnName(0)) + 10;
    typeColumn.setPreferredWidth(width);
    typeColumn.setMaxWidth(width);
    typeColumn.setMinWidth(width);
    typeColumn.setCellRenderer(new IconTableCellRenderer<Icon>() {

        @Nullable
        @Override
        protected Icon getIcon(@NotNull Icon value, JTable table, int row) {
            return value;
        }

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean focus, int row, int column) {
            super.getTableCellRendererComponent(table, value, selected, focus, row, column);
            setText("");
            return this;
        }

        @Override
        protected boolean isCenterAlignment() {
            return true;
        }
    });
    // Column "Case Sensitive"
    TableColumn todoCaseSensitiveColumn = myPatternsTable.getColumnModel().getColumn(1);
    width = myPatternsTable.getFontMetrics(myPatternsTable.getFont()).stringWidth(myPatternsTable.getColumnName(1)) + 10;
    todoCaseSensitiveColumn.setPreferredWidth(width);
    todoCaseSensitiveColumn.setMaxWidth(width);
    todoCaseSensitiveColumn.setMinWidth(width);
    todoCaseSensitiveColumn.setCellRenderer(new BooleanTableCellRenderer());
    todoCaseSensitiveColumn.setCellEditor(new BooleanTableCellEditor());
    // Column "Pattern"
    TodoPatternTableCellRenderer todoPatternRenderer = new TodoPatternTableCellRenderer(myPatterns);
    TableColumn patternColumn = myPatternsTable.getColumnModel().getColumn(2);
    patternColumn.setCellRenderer(todoPatternRenderer);
    JPanel patternsPanel = new JPanel(new BorderLayout());
    patternsPanel.setBorder(IdeBorderFactory.createTitledBorder(IdeBundle.message("label.todo.patterns"), false));
    patternsPanel.add(ToolbarDecorator.createDecorator(myPatternsTable).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            stopEditing();
            TodoPattern pattern = new TodoPattern(TodoAttributesUtil.createDefault());
            PatternDialog dialog = new PatternDialog(myPanel, pattern);
            if (!dialog.showAndGet()) {
                return;
            }
            myPatterns.add(pattern);
            int index = myPatterns.size() - 1;
            myPatternsModel.fireTableRowsInserted(index, index);
            myPatternsTable.getSelectionModel().setSelectionInterval(index, index);
            myPatternsTable.scrollRectToVisible(myPatternsTable.getCellRect(index, 0, true));
        }
    }).setEditAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            editSelectedPattern();
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            stopEditing();
            int selectedIndex = myPatternsTable.getSelectedRow();
            if (selectedIndex < 0 || selectedIndex >= myPatternsModel.getRowCount()) {
                return;
            }
            TodoPattern patternToBeRemoved = myPatterns.get(selectedIndex);
            TableUtil.removeSelectedItems(myPatternsTable);
            for (int i = 0; i < myFilters.size(); i++) {
                TodoFilter filter = myFilters.get(i);
                if (filter.contains(patternToBeRemoved)) {
                    filter.removeTodoPattern(patternToBeRemoved);
                    myFiltersModel.fireTableRowsUpdated(i, i);
                }
            }
        }
    }).disableUpDownActions().createPanel(), BorderLayout.CENTER);
    // double click in "Patterns" table should also start editing of selected pattern
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            editSelectedPattern();
            return true;
        }
    }.installOn(myPatternsTable);
    // Panel with filters
    myFiltersTable = new JBTable(myFiltersModel);
    myFiltersTable.getEmptyText().setText(IdeBundle.message("text.todo.no.filters"));
    // Column "Name"
    TableColumn nameColumn = myFiltersTable.getColumnModel().getColumn(0);
    width = myPatternsTable.getColumnModel().getColumn(0).getPreferredWidth() + /*typeColumn*/
    myPatternsTable.getColumnModel().getColumn(1).getPreferredWidth();
    nameColumn.setPreferredWidth(width);
    nameColumn.setMaxWidth(width);
    nameColumn.setMinWidth(width);
    nameColumn.setCellRenderer(new MyFilterNameTableCellRenderer());
    JPanel filtersPanel = new JPanel(new BorderLayout());
    filtersPanel.setBorder(IdeBorderFactory.createTitledBorder(IdeBundle.message("label.todo.filters"), false));
    filtersPanel.add(ToolbarDecorator.createDecorator(myFiltersTable).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            stopEditing();
            TodoFilter filter = new TodoFilter();
            FilterDialog dialog = new FilterDialog(myPanel, filter, -1, myFilters, myPatterns);
            if (dialog.showAndGet()) {
                myFilters.add(filter);
                int index = myFilters.size() - 1;
                myFiltersModel.fireTableRowsInserted(index, index);
                myFiltersTable.getSelectionModel().setSelectionInterval(index, index);
                myFiltersTable.scrollRectToVisible(myFiltersTable.getCellRect(index, 0, true));
            }
        }
    }).setEditAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            editSelectedFilter();
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            stopEditing();
            TableUtil.removeSelectedItems(myFiltersTable);
        }
    }).disableUpDownActions().createPanel());
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            editSelectedFilter();
            return true;
        }
    }.installOn(myFiltersTable);
    myPanel = FormBuilder.createFormBuilder().addComponentFillVertically(patternsPanel, 0).addComponentFillVertically(filtersPanel, 0).getPanel();
    return myPanel;
}
Also used : TodoFilter(com.intellij.ide.todo.TodoFilter) JBTable(com.intellij.ui.table.JBTable) TodoPattern(com.intellij.psi.search.TodoPattern) MouseEvent(java.awt.event.MouseEvent) TableColumn(javax.swing.table.TableColumn) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with TodoPattern

use of com.intellij.psi.search.TodoPattern in project intellij-community by JetBrains.

the class TodoConfigurable method arePatternsModified.

private boolean arePatternsModified() {
    TodoConfiguration todoConfiguration = TodoConfiguration.getInstance();
    TodoPattern[] initialPatterns = getTodoPatternsToDisplay(todoConfiguration);
    if (initialPatterns.length != myPatterns.size()) {
        return true;
    }
    for (TodoPattern initialPattern : initialPatterns) {
        if (!myPatterns.contains(initialPattern)) {
            return true;
        }
    }
    return false;
}
Also used : TodoPattern(com.intellij.psi.search.TodoPattern) TodoConfiguration(com.intellij.ide.todo.TodoConfiguration)

Example 9 with TodoPattern

use of com.intellij.psi.search.TodoPattern in project intellij-community by JetBrains.

the class TodoPatternTableCellRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    TodoPattern pattern = myPatterns.get(row);
    if (isSelected) {
        setForeground(UIUtil.getTableSelectionForeground());
    } else {
        setForeground(pattern.getPattern() != null ? UIUtil.getTableForeground() : JBColor.RED);
    }
    return this;
}
Also used : TodoPattern(com.intellij.psi.search.TodoPattern)

Aggregations

TodoPattern (com.intellij.psi.search.TodoPattern)9 TodoFilter (com.intellij.ide.todo.TodoFilter)3 TodoConfiguration (com.intellij.ide.todo.TodoConfiguration)2 Element (org.jdom.Element)2 TodoCacheManager (com.intellij.psi.impl.cache.TodoCacheManager)1 JBTable (com.intellij.ui.table.JBTable)1 MouseEvent (java.awt.event.MouseEvent)1 Iterator (java.util.Iterator)1 TableColumn (javax.swing.table.TableColumn)1 Nullable (org.jetbrains.annotations.Nullable)1