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.server.core.partition.impl.btree.gui;
021
022
023 import java.awt.Dimension;
024 import java.awt.Toolkit;
025
026 import org.apache.directory.server.core.partition.impl.btree.BTreePartition;
027 import org.apache.directory.shared.ldap.schema.SchemaManager;
028 import org.slf4j.Logger;
029 import org.slf4j.LoggerFactory;
030
031
032 /**
033 * A partition database viewer.
034 *
035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
036 * @version $Rev: 896599 $
037 */
038 public class PartitionViewer
039 {
040 private static final Logger LOG = LoggerFactory.getLogger( PartitionViewer.class );
041
042 /** A handle on the atomic partition */
043 private BTreePartition partition;
044
045 /** A handle on the global schemaManager */
046 private SchemaManager schemaManager;
047
048
049 public PartitionViewer( BTreePartition db, SchemaManager schemaManager )
050 {
051 this.partition = db;
052 this.schemaManager = schemaManager;
053 }
054
055
056 // added return value so expressions in debugger does not freak with void
057 public int execute() throws Exception
058 {
059 Thread t = new Thread( new Runnable() {
060 public void run()
061 {
062 PartitionFrame frame = null;
063 try
064 {
065 frame = new PartitionFrame( PartitionViewer.this.partition, schemaManager );
066 }
067 catch ( Exception e )
068 {
069 e.printStackTrace();
070 return;
071 }
072 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
073 Dimension frameSize = frame.getSize();
074 frameSize.height = ( ( frameSize.height > screenSize.height ) ? screenSize.height : frameSize.height );
075 frameSize.width = ( ( frameSize.width > screenSize.width ) ? screenSize.width : frameSize.width );
076 frame.setLocation( ( screenSize.width - frameSize.width ) / 2, ( screenSize.height - frameSize.height ) / 2 );
077
078 frame.setVisible( true );
079 LOG.debug( frameSize + "" );
080 }
081 });
082
083 t.run();
084 return 0;
085 }
086 }