All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.intellij.openapi.vcs.ChangeListColumn Maven / Gradle / Ivy

/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Created by IntelliJ IDEA.
 * User: yole
 * Date: 27.11.2006
 * Time: 20:22:50
 */
package com.intellij.openapi.vcs;

import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vcs.changes.ChangeList;
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
import com.intellij.util.text.DateFormatUtil;
import org.jetbrains.annotations.Nullable;

import java.util.Comparator;

public abstract class ChangeListColumn {
  public abstract String getTitle();
  public abstract Object getValue(T changeList);

  @Nullable
  public Comparator getComparator() {
    return null;
  }

  // TODO: CompositeCommittedChangesProvider.getColumns() needs to be updated if new standard columns are added 

  public static ChangeListColumn DATE = new ChangeListColumn() {
    public String getTitle() {
      return VcsBundle.message("column.name.revision.list.date");
    }

    public Object getValue(final CommittedChangeList changeList) {
      return DateFormatUtil.formatPrettyDateTime(changeList.getCommitDate());
    }

    public Comparator getComparator() {
      // TODO: CommittedChangeListByDateComparator could be utilized here. But currently it is placed in vcs-impl.
      // TODO: Think of either moving these ChangeListColumn instances to vcs-impl or move comparator to vcs-api.
      return new Comparator() {
        public int compare(final CommittedChangeList o1, final CommittedChangeList o2) {
          return o1.getCommitDate().compareTo(o2.getCommitDate());
        }
      };
    }
  };

  public static ChangeListColumn NAME = new ChangeListColumn() {
    public String getTitle() {
      return VcsBundle.message("column.name.revision.list.committer");
    }

    public Object getValue(final CommittedChangeList changeList) {
      return changeList.getCommitterName();
    }

    public Comparator getComparator() {
      return new Comparator() {
        public int compare(final CommittedChangeList o1, final CommittedChangeList o2) {
          return Comparing.compare((String) getValue(o1), (String) getValue(o2));
        }
      };
    }
  };

  public static ChangeListColumn NUMBER = new ChangeListNumberColumn(VcsBundle.message("column.name.revision.list.number"));

  public static ChangeListColumn DESCRIPTION = new ChangeListColumn() {
    public String getTitle() {
      return VcsBundle.message("column.name.revision.list.description");
    }

    public Object getValue(final CommittedChangeList changeList) {
      return changeList.getName();
    }

    public Comparator getComparator() {
      return new Comparator() {
        public int compare(final CommittedChangeList o1, final CommittedChangeList o2) {
          return o1.getName().compareTo(o2.getName());
        }
      };
    }
  };

  public static boolean isCustom(final ChangeListColumn column) {
    return column != DATE && column != DESCRIPTION &&
        column != NAME && !(column instanceof ChangeListNumberColumn);
  }

  public static class ChangeListNumberColumn extends ChangeListColumn {
    private final String myTitle;

    public ChangeListNumberColumn(final String title) {
      myTitle = title;
    }

    public String getTitle() {
      return myTitle;
    }

    public Object getValue(final CommittedChangeList changeList) {
      return changeList.getNumber();
    }

    public Comparator getComparator() {
      return new Comparator() {
        public int compare(final CommittedChangeList o1, final CommittedChangeList o2) {
          return (int)(o1.getNumber() - o2.getNumber());
        }
      };
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy