KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > CompositeChangeNode


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ltk.internal.ui.refactoring;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.ltk.core.refactoring.Change;
17 import org.eclipse.ltk.core.refactoring.CompositeChange;
18
19 import org.eclipse.jface.resource.ImageDescriptor;
20
21 public class CompositeChangeNode extends AbstractChangeNode {
22     
23     private final RefactoringPreviewChangeFilter fFilter;
24
25     public CompositeChangeNode(PreviewNode parent, RefactoringPreviewChangeFilter filter, CompositeChange change) {
26         super(parent, change);
27         fFilter= filter;
28     }
29     
30     int getActive() {
31         return getCompositeChangeActive();
32     }
33
34     public ImageDescriptor getImageDescriptor() {
35         return RefactoringPluginImages.DESC_OBJS_COMPOSITE_CHANGE;
36     }
37     
38     PreviewNode[] doCreateChildren() {
39         List JavaDoc children= new ArrayList JavaDoc();
40         getFlattendedChildren(children, this, (CompositeChange)getChange());
41         return (PreviewNode[])children.toArray(new PreviewNode[children.size()]);
42     }
43     
44     private void getFlattendedChildren(List JavaDoc result, CompositeChangeNode parent, CompositeChange focus) {
45         Change[] changes= focus.getChildren();
46         for (int i= 0; i < changes.length; i++) {
47             Change change= changes[i];
48             if (fFilter == null || fFilter.select(change)) {
49                 if (change instanceof CompositeChange && ((CompositeChange) change).isSynthetic()) {
50                     getFlattendedChildren(result, parent, (CompositeChange) change);
51                 } else {
52                     result.add(createNode(parent, change));
53                 }
54             }
55         }
56     }
57 }
Popular Tags