This project has retired. For details please refer to its Attic page.
RelationshipTable xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.workbench.details;
20  
21  import java.awt.event.MouseEvent;
22  
23  import org.apache.chemistry.opencmis.client.api.ObjectId;
24  import org.apache.chemistry.opencmis.client.api.Relationship;
25  import org.apache.chemistry.opencmis.workbench.ClientHelper;
26  import org.apache.chemistry.opencmis.workbench.model.ClientModel;
27  
28  public class RelationshipTable extends AbstractDetailsTable {
29  
30      private static final long serialVersionUID = 1L;
31  
32      private static final String[] COLUMN_NAMES = { "Name", "Type", "Relationship Id", "Source", "Target" };
33      private static final int[] COLUMN_WIDTHS = { 200, 200, 200, 200, 200 };
34  
35      public RelationshipTable(ClientModel model) {
36          super();
37          init(model, COLUMN_NAMES, COLUMN_WIDTHS);
38      }
39  
40      @Override
41      public void singleClickAction(MouseEvent e, int rowIndex, int colIndex) {
42          if (getColumnClass(colIndex) != ObjectId.class) {
43              return;
44          }
45  
46          ObjectId id = (ObjectId) getValueAt(rowIndex, colIndex);
47          if ((id == null) || (id.getId() == null)) {
48              return;
49          }
50  
51          try {
52              getClientModel().loadObject(id.getId());
53              setTab(0);
54          } catch (Exception ex) {
55              ClientHelper.showError(this, ex);
56          }
57      }
58  
59      @Override
60      public int getDetailRowCount() {
61          if (getObject().getRelationships() == null) {
62              return 0;
63          }
64  
65          return getObject().getRelationships().size();
66      }
67  
68      @Override
69      public Object getDetailValueAt(int rowIndex, int columnIndex) {
70          Relationship relationship = getObject().getRelationships().get(rowIndex);
71  
72          switch (columnIndex) {
73          case 0:
74              return relationship.getName();
75          case 1:
76              return relationship.getType().getId();
77          case 2:
78              return relationship;
79          case 3:
80              return relationship.getSourceId();
81          case 4:
82              return relationship.getTarget();
83          }
84  
85          return null;
86      }
87  
88      @Override
89      public Class<?> getDetailColumClass(int columnIndex) {
90          if ((columnIndex == 2) || (columnIndex == 3) || (columnIndex == 4)) {
91              return ObjectId.class;
92          }
93  
94          return super.getDetailColumClass(columnIndex);
95      }
96  }