directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1678108 - in /directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages: ServerIdWrapper.java ServerIdWrapperLabelProvider.java ServerIdWrapperViewerSorter.java
Date Wed, 06 May 2015 23:03:26 GMT
Author: elecharny
Date: Wed May  6 23:03:25 2015
New Revision: 1678108

URL: http://svn.apache.org/r1678108
Log:
Added the ServerId wrapper, and the associated classes

Added:
    directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapper.java
    directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapperLabelProvider.java
    directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapperViewerSorter.java

Added: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapper.java?rev=1678108&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapper.java
(added)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapper.java
Wed May  6 23:03:25 2015
@@ -0,0 +1,120 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.openldap.config.editor.pages;
+
+/**
+ * A wrapper for a ServerID which can be either an integer between 0 and 4095 
+ * (or from 0x0 to 0xFFF), and may be followed by an URL. We can't have both format,
+ * and if it's not an URL, then only one value is accepted
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ServerIdWrapper
+{
+    /** The server ID */
+    int serverId;
+    
+    /** The URL, if any */
+    String url;
+
+    /**
+     * Creates a new instance of ServerIdWrapper.
+     *
+     * @param serverId the serverID
+     */
+    public ServerIdWrapper( int serverId )
+    {
+        this.serverId = serverId;
+    }
+
+    
+    /**
+     * Creates a new instance of ServerIdWrapper.
+     *
+     * @param serverId the serverID
+     * @param url the URL
+     */
+    public ServerIdWrapper( int serverId, String url )
+    {
+        this.serverId = serverId;
+        this.url = url;
+    }
+
+    
+    /**
+     * Creates a new instance of ServerIdWrapper.
+     *
+     * @param serverIdStr the serverID
+     */
+    public ServerIdWrapper( String serverIdStr )
+    {
+        this.serverId = Integer.parseInt( serverIdStr );
+    }
+
+    
+    /**
+     * @return the serverId
+     */
+    public int getServerId()
+    {
+        return serverId;
+    }
+
+    /**
+     * @param serverId the serverId to set
+     */
+    public void setServerId( int serverId )
+    {
+        this.serverId = serverId;
+    }
+    
+    
+    /**
+     * @return the url
+     */
+    public String getUrl()
+    {
+        return url;
+    }
+
+    /**
+     * @param url the url to set
+     */
+    public void setUrl( String url )
+    {
+        this.url = url;
+    }
+    
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        if ( url == null )
+        {
+            return Integer.toString( serverId );
+        }
+        else
+        {
+            return Integer.toString( serverId ) + " " + url;
+        }
+    }
+}

Added: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapperLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapperLabelProvider.java?rev=1678108&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapperLabelProvider.java
(added)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapperLabelProvider.java
Wed May  6 23:03:25 2015
@@ -0,0 +1,55 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.openldap.config.editor.pages;
+
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * This class defines a label provider for a ServerID wrapper viewer.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ServerIdWrapperLabelProvider extends LabelProvider
+{
+    /**
+     * Construct the label for a ServerID. It can be a number in [0..999], or an URL
+     */
+    public String getText( Object element )
+    {
+        if ( element instanceof ServerIdWrapper )
+        {
+            String serverIdtext = ( ( ServerIdWrapper ) element ).toString();
+
+            return serverIdtext;
+        }
+
+        return super.getText( element );
+    };
+
+
+    /**
+     * Get the image. We have none (may be we could add one for URLs ?)
+     */
+    public Image getImage( Object element )
+    {
+        return null;
+    };
+}

Added: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapperViewerSorter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapperViewerSorter.java?rev=1678108&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapperViewerSorter.java
(added)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/ServerIdWrapperViewerSorter.java
Wed May  6 23:03:25 2015
@@ -0,0 +1,59 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.openldap.config.editor.pages;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+
+/**
+ * This class defines a sorter for a ServerID wrapper viewer.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ServerIdWrapperViewerSorter extends ViewerSorter
+{
+    public int compare( Viewer viewer, Object e1, Object e2 )
+    {
+        if ( ( e1 != null ) && ( e2 != null ) && ( e1 instanceof ServerIdWrapper
)
+            && ( e2 instanceof ServerIdWrapper ) )
+        {
+            ServerIdWrapper serverIdWrapper1 = ( ServerIdWrapper ) e1;
+            ServerIdWrapper serverIdWrapper2 = ( ServerIdWrapper ) e2;
+            int serverId1 = serverIdWrapper1.getServerId();
+            int serverId2 = serverIdWrapper2.getServerId();
+
+            if ( serverId1 > serverId2 )
+            {
+                return 1;
+            }
+            else if ( serverId1 < serverId2 )
+            {
+                return -1;
+            }
+            else 
+            {
+                // This is actually an error...
+                return 1;
+            }
+        }
+
+        return super.compare( viewer, e1, e2 );
+    }
+}



Mime
View raw message