001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.studio.apacheds.views;
021
022
023 import org.apache.directory.studio.apacheds.ApacheDsPlugin;
024 import org.apache.directory.studio.apacheds.ApacheDsPluginConstants;
025 import org.apache.directory.studio.apacheds.model.Server;
026 import org.apache.directory.studio.apacheds.model.ServerStateEnum;
027 import org.eclipse.jface.viewers.ITableLabelProvider;
028 import org.eclipse.jface.viewers.LabelProvider;
029 import org.eclipse.swt.graphics.Image;
030
031
032 /**
033 * This class implements the label provider for the Servers view.
034 *
035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
036 * @version $Rev$, $Date$
037 */
038 public class ServersViewLabelProvider extends LabelProvider implements ITableLabelProvider
039 {
040 private static final String THREE_DOTS = "..."; //$NON-NLS-1$
041 private static final String TWO_DOTS = ".."; //$NON-NLS-1$
042 private static final String ONE_DOT = "."; //$NON-NLS-1$
043 private int count = 1;
044
045
046 /* (non-Javadoc)
047 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
048 */
049 public String getColumnText( Object element, int columnIndex )
050 {
051 if ( element instanceof Server )
052 {
053 Server server = ( Server ) element;
054 if ( columnIndex == 0 )
055 {
056 return server.getName();
057 }
058 else if ( columnIndex == 1 )
059 {
060 ServerStateEnum state = ( ( Server ) element ).getState();
061 switch ( state )
062 {
063 case STARTED:
064 return state.toString();
065 case STARTING:
066 return state.toString() + getDots();
067 case STOPPED:
068 return state.toString();
069 case STOPPING:
070 return state.toString() + getDots();
071 case UNKNONW:
072 return state.toString();
073 }
074 }
075
076 }
077
078 return null;
079 }
080
081
082 private String getDots()
083 {
084 if ( count == 1 )
085 {
086 return ServersViewLabelProvider.ONE_DOT;
087 }
088 else if ( count == 2 )
089 {
090 return ServersViewLabelProvider.TWO_DOTS;
091 }
092 else
093 {
094 return ServersViewLabelProvider.THREE_DOTS;
095 }
096 }
097
098
099 /* (non-Javadoc)
100 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
101 */
102 public Image getColumnImage( Object element, int columnIndex )
103 {
104 if ( element instanceof Server )
105 {
106 if ( columnIndex == 0 )
107 {
108 return ApacheDsPlugin.getDefault().getImage( ApacheDsPluginConstants.IMG_SERVER );
109 }
110 else if ( columnIndex == 1 )
111 {
112 switch ( ( ( Server ) element ).getState() )
113 {
114 case STARTED:
115 return ApacheDsPlugin.getDefault().getImage( ApacheDsPluginConstants.IMG_SERVER_STARTED );
116 case STARTING:
117 switch ( count )
118 {
119 case 1:
120 return ApacheDsPlugin.getDefault().getImage(
121 ApacheDsPluginConstants.IMG_SERVER_STARTING1 );
122 case 2:
123 return ApacheDsPlugin.getDefault().getImage(
124 ApacheDsPluginConstants.IMG_SERVER_STARTING2 );
125 case 3:
126 return ApacheDsPlugin.getDefault().getImage(
127 ApacheDsPluginConstants.IMG_SERVER_STARTING3 );
128 }
129 case STOPPED:
130 return ApacheDsPlugin.getDefault().getImage( ApacheDsPluginConstants.IMG_SERVER_STOPPED );
131 case STOPPING:
132 switch ( count )
133 {
134 case 1:
135 return ApacheDsPlugin.getDefault().getImage(
136 ApacheDsPluginConstants.IMG_SERVER_STOPPING1 );
137 case 2:
138 return ApacheDsPlugin.getDefault().getImage(
139 ApacheDsPluginConstants.IMG_SERVER_STOPPING2 );
140 case 3:
141 return ApacheDsPlugin.getDefault().getImage(
142 ApacheDsPluginConstants.IMG_SERVER_STOPPING3 );
143 }
144 case UNKNONW:
145 return ApacheDsPlugin.getDefault().getImage( ApacheDsPluginConstants.IMG_SERVER );
146 }
147 }
148 }
149
150 return null;
151 }
152
153
154 /**
155 * Increase the counter of the animation.
156 */
157 public void animate()
158 {
159 count++;
160
161 if ( count > 3 )
162 {
163 count = 1;
164 }
165 }
166 }