1

アウトラインビューでのノードプロパティの処理について質問があります。

私には3つのレベルのノードがあります。rootNode、ノード、そして各ノードにはサブノードがあります。rootNodeを除いて、すべてのノードとサブノードは同じ(ブール値=>チェックボックス)プロパティを持つ必要があります。アウトラインビューには、ノード列とチェックボックス付きのプロパティ列の2つの列があります。

今必要なのは、ノードのチェックボックスをアクティブにすると、そのすべてのサブノードのチェックボックスもアクティブになり、ノードのチェックボックスを非アクティブにすると、そのすべてのサブノードのチェックボックスが非アクティブになるという動作です。同じように。ツリーを展開してサブノードを表示すると、各サブノードも選択される場合があります。

私の現在のコードは次のようになります(一部はインターネット上にあります)。

メインAPI

public class Category {

    private String name;
    private Boolean x;

    public Category() {
        this("empty");
    }

    public Category(String name) {
        this.name = name;
    }

    public Category(String name, Boolean x) {
        this.name = name;
        this.x = x;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getx() {
        return x;
    }

    public void setx(Boolean x) {
        this.x = x;
    }
}

ノード(カテゴリ)の私のChildFactoryは次のようになります

public class CategoryChildrenFactory extends ChildFactory.Detachable<Category> {

    /* detachable has no real effect on the current code, used to control 
    the life cylce */
    @Override
    protected boolean createKeys(List<Category> toPopulate) {

        toPopulate.add(new Category("Cat1", false));
        toPopulate.add(new Category("Cat2", false));
        toPopulate.add(new Category("Cat3", false));

        return true;
    }

    @Override
    protected Node createNodeForKey(Category key) {
        AllNode cn = new AllNode(key);
        return cn;
    }
}

およびサブノードの場合

public class MovieChildrenFactory extends ChildFactory<String>{

    Category category;

    public MovieChildrenFactory(Category category) {
        this.category = category;
    }

    @Override
    protected boolean createKeys(List<String> toPopulate) {
        toPopulate.add("m_1");
        toPopulate.add("m_2");
        toPopulate.add("m_3");

        return true;
    }

    @Override
    protected Node createNodeForKey(String key) {
        return new AllNode(category, key);
    }
}

ノードの作成は、両方のタイプ(ノード、サブノード)の単一のクラスに入れられます

public class AllNode extends AbstractNode {

    Category category;
    String title;
    private Sheet.Set set;

    public AllNode(Category category) {
        this(category, null);
        this.category = category;
        set = Sheet.createPropertiesSet();
    }

    public AllNode(Category category, String title) {
        super(Children.LEAF, Lookups.singleton(category));
        if (title == null) {
            this.setChildren(Children.create(new MovieChildrenFactory(category), true));
        }
        this.title = title;
        set = Sheet.createPropertiesSet();
    }

    @Override
    public String getHtmlDisplayName() {
        String name = "";
        if (title == null) {
            name = category.getName();
        } else {
            name = title;
        }
        return name;
    }

    @Override
    protected Sheet createSheet() {
        Sheet sheet = Sheet.createDefault();
        Category obj = getLookup().lookup(Category.class);
        PlotMathProperties pmp = new PlotMathProperties(obj, title);
        set.put(pmp.getMyProperty());
        sheet.put(set);
        return sheet;
    }
}

プロパティはによって処理されます

public class PlotMathProperties {

    private MyProperty myProperty;
    private String categoryName;
    private String title;

    public PlotMathProperties(Category category, String title) {
        this.categoryName = category.getName();
        this.title= title;
        this.myProperty= new MyProperty ();
    }

    public XProperty getMyProperty () {
        return myProperty;
    }

    public class MyProperty extends PropertySupport.ReadWrite<Boolean> {

        private Boolean isMyProp = false;

        public MyProperty () {
            super("x", Boolean.class, "XPROP", "Is this a coloured or black and white movie");
        }

        @Override
        public Boolean getValue() throws IllegalAccessException, InvocationTargetException {
            return isMyProp ;
        }

        @Override
        public void setValue(Boolean val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
            isMyProp = val;
            if (isMyProp) {
                System.out.println("active: " + categoryName + ", " + title);
            } else {
                System.out.println("de-active: " + categoryName + ", " + title);
            }
        }
    }
}

TopComponentと一緒に使用すると、アウトラインビューは見栄えがよく、うまく機能します。

チェックボックスの動作を設定する方法を誰かが知っていますか

よろしく

4

0 に答える 0