ComponentWithBrowseButton - optional remove listener on hide
[fedora-idea.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / Modifier.java
bloba3317e39667d957495208ba701ba507161477202
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.vcs.changes;
18 import com.intellij.openapi.vcs.changes.local.*;
19 import com.intellij.util.containers.MultiMap;
20 import org.jetbrains.annotations.NotNull;
22 import java.util.LinkedList;
23 import java.util.List;
25 /** synchronization aspect is external for this class; only logic here
26 * have internal command queue; applies commands to another copy of change lists (ChangeListWorker) and sends notifications
27 * (after update is done)
29 public class Modifier implements ChangeListsWriteOperations {
30 private final ChangeListWorker myWorker;
31 private boolean myInsideUpdate;
32 private final List<ChangeListCommand> myCommandQueue;
33 private final DelayedNotificator myNotificator;
35 public Modifier(final ChangeListWorker worker, final DelayedNotificator notificator) {
36 myWorker = worker;
37 myNotificator = notificator;
38 myCommandQueue = new LinkedList<ChangeListCommand>();
41 public LocalChangeList addChangeList(@NotNull final String name, final String comment) {
42 final AddList command = new AddList(name, comment);
43 impl(command);
44 return command.getNewListCopy();
47 public String setDefault(final String name) {
48 final SetDefault command = new SetDefault(name);
49 impl(command);
50 return command.getPrevious();
53 public boolean removeChangeList(@NotNull final String name) {
54 final RemoveList command = new RemoveList(name);
55 impl(command);
56 return command.isRemoved();
59 public MultiMap<LocalChangeList, Change> moveChangesTo(final String name, final Change[] changes) {
60 final MoveChanges command = new MoveChanges(name, changes);
61 impl(command);
62 return command.getMovedFrom();
65 private void impl(final ChangeListCommand command) {
66 command.apply(myWorker);
67 if (myInsideUpdate) {
68 myCommandQueue.add(command);
69 // notify after change lsist are synchronized
70 } else {
71 // notify immediately
72 myNotificator.callNotify(command);
76 public boolean setReadOnly(final String name, final boolean value) {
77 final SetReadOnly command = new SetReadOnly(name, value);
78 impl(command);
79 return command.isResult();
82 public boolean editName(@NotNull final String fromName, @NotNull final String toName) {
83 final EditName command = new EditName(fromName, toName);
84 impl(command);
85 return command.isResult();
88 public String editComment(@NotNull final String fromName, final String newComment) {
89 final EditComment command = new EditComment(fromName, newComment);
90 impl(command);
91 return command.getOldComment();
94 public boolean isInsideUpdate() {
95 return myInsideUpdate;
98 public void enterUpdate() {
99 myInsideUpdate = true;
102 public void exitUpdate() {
103 myInsideUpdate = false;
106 public void clearQueue() {
107 myCommandQueue.clear();
110 public void apply(final ChangeListWorker worker) {
111 for (ChangeListCommand command : myCommandQueue) {
112 command.apply(worker);
113 myNotificator.callNotify(command);