1// BEGIN LICENSE BLOCK
2// Version: CMPL 1.1
3//
4// The contents of this file are subject to the Cisco-style Mozilla Public
5// License Version 1.1 (the "License"); you may not use this file except
6// in compliance with the License.  You may obtain a copy of the License
7// at www.eclipse-clp.org/license.
8//
9// Software distributed under the License is distributed on an "AS IS"
10// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11// the License for the specific language governing rights and limitations
12// under the License.
13//
14// The Original Code is  The ECLiPSe Constraint Logic Programming System.
15// The Initial Developer of the Original Code is  Cisco Systems, Inc.
16// Portions created by the Initial Developer are
17// Copyright (C) 2006 Cisco Systems, Inc.  All Rights Reserved.
18//
19// Contributor(s):
20//
21// END LICENSE BLOCK
22
23package com.parctechnologies.eclipse.visualisation;
24
25import java.util.*;
26import javax.swing.*;
27import java.awt.event.*;
28import java.beans.*;
29
30/**
31 * Provides a concrete implementation of the ViewletSelection interface.
32 */
33public class ViewletSelectionImpl extends HashSet implements ViewletSelection
34{
35  // Return a collection of common actions.
36  // Each action in the collection is a compound
37  // action. There is one compound action in the collection
38  // for each action which is common to all viewlets in the selection.
39  public Collection getCommonActions()
40  {
41    Collection commonActions = new LinkedList();
42    Collection firstViewletsActions;
43    ViewletAction currentAction;
44    Iterator viewletsIterator;
45    Iterator firstViewletsActionsIterator;
46    Viewlet firstViewlet, currentViewlet;
47    List currentViewletActions;
48    boolean allContainAction;
49
50    if(isEmpty())
51    {
52      return(Collections.EMPTY_SET);
53    }
54    firstViewlet = (Viewlet) (iterator().next());
55    firstViewletsActions = firstViewlet.getActions();
56    firstViewletsActionsIterator = firstViewletsActions.iterator();
57
58    // for each currentAction in the first viewlet's actions
59    while(firstViewletsActionsIterator.hasNext())
60    {
61      currentAction = (ViewletAction) firstViewletsActionsIterator.next();
62      viewletsIterator = iterator();
63      allContainAction = true;
64      // test whether each viewlet has an action equals() to currentAction
65      while(viewletsIterator.hasNext() && allContainAction)
66      {
67        currentViewlet = (Viewlet) viewletsIterator.next();
68        if(!currentViewlet.getActions().contains(currentAction))
69        {
70          allContainAction = false;
71        }
72      }
73      if(allContainAction)
74      {
75        commonActions.add(currentAction.createCompoundAction(this));
76      }
77    }
78    return(commonActions);
79  }
80}
81
82