技術をかじる猫

適当に気になった技術や言語、思ったこと考えた事など。

WPFのTreeViewいじってみた。

バインド対象のモデル。
やべ、C#は覚えてるけど、WPFは2年いじってないからほぼ忘れた(;・∀・)
ここ眺めながら必死に思い出す。

class ModelDataValue : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public ModelDataValue(ModelDataValue parent, string path)
    {
        if (!Directory.Exists(path))
            throw new ArgumentException("path not found :" + path, path);

        this.info = new DirectoryInfo(path);
        this.parentNode = parent;
        this.children = null;
    }

    private ModelDataValue parentNode;
    private DirectoryInfo info;
    private ReadOnlyCollection<ModelDataValue> children;
    private bool _isExpanded;
    private bool _isSelected;

    public string Name
    {
        get { return info.Name; }
    }

    public ModelDataValue Parent
    {
        get { return this.parentNode; }
    }

    public bool IsExpanded
    {
        get { return this._isExpanded; }
        set
        {
            if (this._isExpanded == value) return;
            this._isExpanded = value;
            this.OnPropertyChanged("IsExpanded");
        }
    }

    public bool HasNoChildren
    {
        get
        {
            return this.children == null;
        }
    }

    public bool IsSelected
    {
        get { return this._isSelected; }
        set
        {
            if (this._isSelected == value) return;
            this._isSelected = value;
            this.OnPropertyChanged("IsSelected");
        }
    }

    public ReadOnlyCollection<ModelDataValue> Children
    {
        get
        {
            this.CreateChildren();
            return this.children;
        }
    }

    private void CreateChildren()
    {
        if (this.HasNoChildren)
        {
            List<ModelDataValue> lists = new List<ModelDataValue>();
            foreach (var directoryInfo in this.info.GetDirectories())
            {
                lists.Add(new ModelDataValue(this, directoryInfo.FullName));
            }

            this.children = new ReadOnlyCollection<ModelDataValue>(lists);
        }
    }

    private void OnPropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            PropertyChangedEventArgs args
                = new PropertyChangedEventArgs(propertyName);
            this.PropertyChanged(this, args);
        }
    }
}

IsSelected と IsExpanded が似てるから、すっごくリファクタしたいけどとりあえず。
Children 初回アクセス時に、子要素を列挙するようにしてる。動的な追加とか知らん。

続きを読む

AndroidSDKを64bit環境に入れてみた

参考にしたサイト:http://d.hatena.ne.jp/hdk_embedded/20090726/1248626274

EclipseJava 以外は特に代わり映えしない。
とりあえず、adb の位置が、android-sdk/tools から、android-sdk/platform-tools に移動してるくらい。
サンプルアプリの動作も確認。

特に 64bit Java の影響をうけているようではない。
とりあえず思ったのは、重い。32bit環境でこんな重かったっけ?とか悩む位。