Search in sources :

Example 1 with CompilerOptionInfo

use of com.intellij.flex.model.bc.CompilerOptionInfo in project intellij-plugins by JetBrains.

the class CompilerOptionsConfigurable method updateChildNodes.

private void updateChildNodes(final DefaultMutableTreeNode rootNode, final CompilerOptionInfo[] optionInfos, final boolean showAll) {
    int currentNodeNumber = 0;
    for (final CompilerOptionInfo info : optionInfos) {
        final boolean show = // empty group will be hidden later
        info.isGroup() || ((myMode != Mode.BC || info.isApplicable(getSdkVersion(), myNature)) && (showAll || !info.ADVANCED || hasCustomValue(info)));
        DefaultMutableTreeNode node = findChildNodeWithInfo(rootNode, info);
        if (show) {
            if (node == null) {
                node = new DefaultMutableTreeNode(info, info.isGroup());
                rootNode.insert(node, currentNodeNumber);
            }
            currentNodeNumber++;
            if (info.isGroup()) {
                updateChildNodes(node, info.getChildOptionInfos(), showAll);
                if (node.getChildCount() == 0) {
                    node.removeFromParent();
                    currentNodeNumber--;
                }
            }
        } else {
            if (node != null) {
                node.removeFromParent();
            }
        }
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CompilerOptionInfo(com.intellij.flex.model.bc.CompilerOptionInfo)

Example 2 with CompilerOptionInfo

use of com.intellij.flex.model.bc.CompilerOptionInfo in project intellij-plugins by JetBrains.

the class CompilerOptionsConfigurable method createValueEditor.

private TableCellEditor createValueEditor() {
    return new AbstractTableCellEditor() {

        //private CellEditorComponentWithBrowseButton<JTextField> myTextWithBrowse;
        //private LocalPathCellEditor myLocalPathCellEditor;
        private final JTextField myTextField = new JTextField();

        private final TextFieldWithBrowseButton myTextWithBrowse = new TextFieldWithBrowseButton();

        private final RepeatableValueEditor myRepeatableValueEditor = new RepeatableValueEditor(myProject);

        private final ExtensionAwareFileChooserDescriptor myFileChooserDescriptor = new ExtensionAwareFileChooserDescriptor();

        private final JCheckBox myCheckBox = new JCheckBox();

        {
            myTextWithBrowse.addBrowseFolderListener(null, null, myProject, myFileChooserDescriptor);
            myCheckBox.addActionListener(new ActionListener() {

                public void actionPerformed(final ActionEvent e) {
                    // apply new check box state immediately
                    TableUtil.stopEditing(myTreeTable);
                }
            });
        }

        private Component myCurrentEditor;

        public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, final int row, int column) {
            assert value instanceof CompilerOptionInfo;
            final CompilerOptionInfo info = (CompilerOptionInfo) value;
            final Sdk sdk = myDependenciesConfigurable.getCurrentSdk();
            final String sdkHome = sdk == null || sdk.getSdkType() == FlexmojosSdkType.getInstance() ? null : sdk.getHomePath();
            final String optionValue = sdkHome == null ? getValueAndSource(info).first : getValueAndSource(info).first.replace(CompilerOptionInfo.FLEX_SDK_MACRO, sdkHome);
            switch(info.TYPE) {
                case Boolean:
                    myCheckBox.setBackground(table.getBackground());
                    myCheckBox.setSelected("true".equalsIgnoreCase(optionValue));
                    myCurrentEditor = myCheckBox;
                    break;
                case List:
                    myRepeatableValueEditor.setInfoAndValue(info, optionValue);
                    myCurrentEditor = myRepeatableValueEditor;
                    break;
                case String:
                case Int:
                case IncludeClasses:
                case IncludeFiles:
                    myTextField.setText(optionValue);
                    myCurrentEditor = myTextField;
                    break;
                case File:
                    myFileChooserDescriptor.setAllowedExtensions(info.FILE_EXTENSION);
                    myTextWithBrowse.setText(FileUtil.toSystemDependentName(optionValue));
                    myCurrentEditor = myTextWithBrowse;
                    break;
                case Group:
                default:
                    assert false;
            }
            return myCurrentEditor;
        }

        public Object getCellEditorValue() {
            if (myCurrentEditor == myCheckBox) {
                return String.valueOf(myCheckBox.isSelected());
            }
            if (myCurrentEditor == myTextField) {
                return myTextField.getText().trim();
            }
            if (myCurrentEditor == myTextWithBrowse) {
                final Sdk sdk = myDependenciesConfigurable.getCurrentSdk();
                final String sdkHome = sdk == null || sdk.getSdkType() == FlexmojosSdkType.getInstance() ? null : sdk.getHomePath();
                final String path = FileUtil.toSystemIndependentName(myTextWithBrowse.getText().trim());
                return sdkHome == null ? path : path.replace(sdkHome, CompilerOptionInfo.FLEX_SDK_MACRO);
            }
            if (myCurrentEditor == myRepeatableValueEditor) {
                final Sdk sdk = myDependenciesConfigurable.getCurrentSdk();
                final String sdkHome = sdk == null ? null : sdk.getHomePath();
                final String value = myRepeatableValueEditor.getValue();
                return sdkHome == null ? value : value.replace(sdkHome, CompilerOptionInfo.FLEX_SDK_MACRO);
            }
            assert false;
            return null;
        }
    };
}
Also used : CompilerOptionInfo(com.intellij.flex.model.bc.CompilerOptionInfo) ActionEvent(java.awt.event.ActionEvent) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) ActionListener(java.awt.event.ActionListener) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 3 with CompilerOptionInfo

use of com.intellij.flex.model.bc.CompilerOptionInfo in project intellij-plugins by JetBrains.

the class CompilerOptionsConfigurable method createColumns.

private ColumnInfo[] createColumns() {
    final ColumnInfo optionColumn = new ColumnInfo("Option") {

        public Object valueOf(final Object o) {
            final Object userObject = ((DefaultMutableTreeNode) o).getUserObject();
            return userObject instanceof CompilerOptionInfo ? userObject : o;
        }

        public Class getColumnClass() {
            return TreeTableModel.class;
        }
    };
    final ColumnInfo valueColumn = new ColumnInfo("Value") {

        public Object valueOf(Object o) {
            final Object userObject = ((DefaultMutableTreeNode) o).getUserObject();
            return userObject instanceof CompilerOptionInfo && !((CompilerOptionInfo) userObject).isGroup() ? userObject : null;
        }

        public Class getColumnClass() {
            return CompilerOptionInfo.class;
        }

        //public TableCellRenderer getRenderer(Object o) {
        //  return myValueRenderer;
        //}
        //public TableCellEditor getEditor(Object item) {
        //  return myEditor;
        //}
        public boolean isCellEditable(Object o) {
            final Object userObject = ((DefaultMutableTreeNode) o).getUserObject();
            return userObject instanceof CompilerOptionInfo && !((CompilerOptionInfo) userObject).isGroup();
        }

        public void setValue(Object node, Object value) {
            final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;
            final CompilerOptionInfo info = (CompilerOptionInfo) treeNode.getUserObject();
            final Pair<String, ValueSource> valueAndSource = getValueAndSource(info);
            // don't apply if user just clicked through the table without typing anything
            if (!value.equals(valueAndSource.first)) {
                myMapModified = true;
                myCurrentOptions.put(info.ID, (String) value);
                reloadNodeOrGroup(myTreeTable.getTree(), treeNode);
            }
        }
    };
    return new ColumnInfo[] { optionColumn, valueColumn };
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CompilerOptionInfo(com.intellij.flex.model.bc.CompilerOptionInfo) ValueSource(com.intellij.flex.model.bc.ValueSource) ColumnInfo(com.intellij.util.ui.ColumnInfo) ListTreeTableModel(com.intellij.ui.treeStructure.treetable.ListTreeTableModel) TreeTableModel(com.intellij.ui.treeStructure.treetable.TreeTableModel)

Example 4 with CompilerOptionInfo

use of com.intellij.flex.model.bc.CompilerOptionInfo in project intellij-plugins by JetBrains.

the class CompilerOptionsConfigurable method createValueRenderer.

private TableCellRenderer createValueRenderer() {
    return new TableCellRenderer() {

        private final JLabel myLabel = new JLabel();

        private final JCheckBox myCheckBox = new JCheckBox();

        private final ComponentWithBrowseButton<JLabel> myLabelWithBrowse = new ComponentWithBrowseButton<>(new JLabel(), null);

        public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
            if (!(value instanceof CompilerOptionInfo)) {
                // invisible root node or group node
                myLabel.setText("");
                return myLabel;
            }
            final CompilerOptionInfo info = (CompilerOptionInfo) value;
            final Pair<String, ValueSource> valueAndSource = getValueAndSource(info);
            switch(info.TYPE) {
                case Boolean:
                    myCheckBox.setBackground(table.getBackground());
                    //myCheckBox.setForeground(UIUtil.getTableForeground());
                    //myCheckBox.setEnabled(moduleDefault || fromConfigFile || custom);
                    myCheckBox.setSelected("true".equalsIgnoreCase(valueAndSource.first));
                    return myCheckBox;
                case String:
                case Int:
                case List:
                case IncludeClasses:
                case IncludeFiles:
                    myLabel.setBackground(table.getBackground());
                    myLabel.setText(getPresentableSummary(valueAndSource.first, info));
                    renderAccordingToSource(myLabel, valueAndSource.second, false);
                    return myLabel;
                case File:
                    final JLabel label = myLabelWithBrowse.getChildComponent();
                    myLabelWithBrowse.setBackground(table.getBackground());
                    label.setText(FileUtil.toSystemDependentName(valueAndSource.first));
                    renderAccordingToSource(label, valueAndSource.second, false);
                    return myLabelWithBrowse;
                case Group:
                default:
                    assert false;
                    return null;
            }
        }
    };
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) CompilerOptionInfo(com.intellij.flex.model.bc.CompilerOptionInfo) ValueSource(com.intellij.flex.model.bc.ValueSource) ComponentWithBrowseButton(com.intellij.openapi.ui.ComponentWithBrowseButton)

Example 5 with CompilerOptionInfo

use of com.intellij.flex.model.bc.CompilerOptionInfo in project intellij-plugins by JetBrains.

the class CompilerOptionsConfigurable method createTreeTable.

private TreeTable createTreeTable() {
    final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    final TreeTableModel model = new ListTreeTableModel(rootNode, createColumns());
    final TreeTable treeTable = new TreeTable(model);
    treeTable.getColumnModel().getColumn(1).setCellRenderer(createValueRenderer());
    treeTable.getColumnModel().getColumn(1).setCellEditor(createValueEditor());
    final TreeTableTree tree = treeTable.getTree();
    tree.setRootVisible(false);
    tree.setLineStyleAngled();
    tree.setShowsRootHandles(true);
    tree.setCellRenderer(createTreeCellRenderer());
    treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    treeTable.setRowHeight(new JTextField("Fake").getPreferredSize().height + 3);
    //treeTable.setTableHeader(null);
    final DefaultActionGroup group = new DefaultActionGroup();
    group.add(new RestoreDefaultValueAction(tree));
    PopupHandler.installPopupHandler(treeTable, group, ActionPlaces.UNKNOWN, ActionManager.getInstance());
    new TreeTableSpeedSearch(treeTable, o -> {
        final Object userObject = ((DefaultMutableTreeNode) o.getLastPathComponent()).getUserObject();
        return userObject instanceof CompilerOptionInfo ? ((CompilerOptionInfo) userObject).DISPLAY_NAME : "";
    }).setComparator(new SpeedSearchComparator(false));
    return treeTable;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) EventDispatcher(com.intellij.util.EventDispatcher) HyperlinkEvent(javax.swing.event.HyperlinkEvent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ColumnInfo(com.intellij.util.ui.ColumnInfo) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) THashMap(gnu.trove.THashMap) TableCellRenderer(javax.swing.table.TableCellRenderer) CompilerUIConfigurable(com.intellij.compiler.options.CompilerUIConfigurable) BCUtils(com.intellij.lang.javascript.flex.projectStructure.options.BCUtils) Nls(org.jetbrains.annotations.Nls) FlexmojosSdkType(com.intellij.lang.javascript.flex.sdk.FlexmojosSdkType) CompilerOptionsListener(com.intellij.lang.javascript.flex.projectStructure.model.CompilerOptionsListener) Disposer(com.intellij.openapi.util.Disposer) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) FileUtil(com.intellij.openapi.util.io.FileUtil) ChangeListener(javax.swing.event.ChangeListener) Module(com.intellij.openapi.module.Module) TreeTable(com.intellij.ui.treeStructure.treetable.TreeTable) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ChangeEvent(javax.swing.event.ChangeEvent) TreePath(javax.swing.tree.TreePath) ActionCallback(com.intellij.openapi.util.ActionCallback) ValueSource(com.intellij.flex.model.bc.ValueSource) TreeTableTree(com.intellij.ui.treeStructure.treetable.TreeTableTree) FlexBundle(com.intellij.lang.javascript.flex.FlexBundle) com.intellij.ui(com.intellij.ui) ComponentWithBrowseButton(com.intellij.openapi.ui.ComponentWithBrowseButton) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) TreeCellRenderer(javax.swing.tree.TreeCellRenderer) CompilerOptions(com.intellij.lang.javascript.flex.projectStructure.model.CompilerOptions) ListTreeTableModel(com.intellij.ui.treeStructure.treetable.ListTreeTableModel) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NamedConfigurable(com.intellij.openapi.ui.NamedConfigurable) NotNull(org.jetbrains.annotations.NotNull) FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) FlexUtils(com.intellij.lang.javascript.flex.FlexUtils) java.util(java.util) ShowSettingsUtil(com.intellij.openapi.options.ShowSettingsUtil) ActionListener(java.awt.event.ActionListener) FlexProjectLevelCompilerOptionsHolder(com.intellij.lang.javascript.flex.projectStructure.FlexProjectLevelCompilerOptionsHolder) ContainerUtil(com.intellij.util.containers.ContainerUtil) History(com.intellij.ui.navigation.History) FlexSdkType2(com.intellij.lang.javascript.flex.sdk.FlexSdkType2) TableCellEditor(javax.swing.table.TableCellEditor) Project(com.intellij.openapi.project.Project) DocumentEvent(javax.swing.event.DocumentEvent) PlatformIcons(com.intellij.util.PlatformIcons) TreeUtil(com.intellij.util.ui.tree.TreeUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) ActionEvent(java.awt.event.ActionEvent) Disposable(com.intellij.openapi.Disposable) Sdk(com.intellij.openapi.projectRoots.Sdk) BuildConfigurationNature(com.intellij.flex.model.bc.BuildConfigurationNature) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Place(com.intellij.ui.navigation.Place) ResourceFilesMode(com.intellij.lang.javascript.flex.projectStructure.model.CompilerOptions.ResourceFilesMode) ModifiableCompilerOptions(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableCompilerOptions) Pair(com.intellij.openapi.util.Pair) PathUtil(com.intellij.util.PathUtil) CompilerOptionInfo(com.intellij.flex.model.bc.CompilerOptionInfo) TreeTableModel(com.intellij.ui.treeStructure.treetable.TreeTableModel) javax.swing(javax.swing) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CompilerOptionInfo(com.intellij.flex.model.bc.CompilerOptionInfo) TreeTable(com.intellij.ui.treeStructure.treetable.TreeTable) ListTreeTableModel(com.intellij.ui.treeStructure.treetable.ListTreeTableModel) TreeTableModel(com.intellij.ui.treeStructure.treetable.TreeTableModel) ListTreeTableModel(com.intellij.ui.treeStructure.treetable.ListTreeTableModel) TreeTableTree(com.intellij.ui.treeStructure.treetable.TreeTableTree)

Aggregations

CompilerOptionInfo (com.intellij.flex.model.bc.CompilerOptionInfo)9 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 ValueSource (com.intellij.flex.model.bc.ValueSource)4 Sdk (com.intellij.openapi.projectRoots.Sdk)2 ComponentWithBrowseButton (com.intellij.openapi.ui.ComponentWithBrowseButton)2 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)2 ListTreeTableModel (com.intellij.ui.treeStructure.treetable.ListTreeTableModel)2 TreeTableModel (com.intellij.ui.treeStructure.treetable.TreeTableModel)2 AbstractTableCellEditor (com.intellij.util.ui.AbstractTableCellEditor)2 ColumnInfo (com.intellij.util.ui.ColumnInfo)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 TableCellRenderer (javax.swing.table.TableCellRenderer)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 CompilerUIConfigurable (com.intellij.compiler.options.CompilerUIConfigurable)1 BuildConfigurationNature (com.intellij.flex.model.bc.BuildConfigurationNature)1 FlexBundle (com.intellij.lang.javascript.flex.FlexBundle)1 FlexUtils (com.intellij.lang.javascript.flex.FlexUtils)1 FlexProjectLevelCompilerOptionsHolder (com.intellij.lang.javascript.flex.projectStructure.FlexProjectLevelCompilerOptionsHolder)1 CompilerOptions (com.intellij.lang.javascript.flex.projectStructure.model.CompilerOptions)1