/*
* Constellation - An open source and standard compliant SDI
* http://www.constellation-sdi.org
*
* Copyright 2014 Geomatys.
*
* Licensed 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.constellation.swing.action;
import org.constellation.configuration.Instance;
import org.constellation.security.ActionPermissions;
import org.constellation.swing.LayerRowModel;
import javax.swing.*;
import java.awt.*;
import java.util.Map;
/**
*
* @author Johann Sorel (Geomatys)
*/
public class ServiceViewAction extends Action {
public ServiceViewAction() {
super(ActionPermissions.VIEW_SERVICE);
}
@Override
public boolean isEnable() {
if (target instanceof Map.Entry) {
final Instance inst = (Instance) ((Map.Entry)target).getKey();
final String type = (String) ((Map.Entry)target).getValue();
final String lowerType = type.toLowerCase();
if(!(lowerType.equals("wms") || lowerType.equals("wmts") || lowerType.equals("wfs"))){
//not a viewable type
return false;
}
return true;
}
return false;
}
@Override
public String getDisplayName() {
return LayerRowModel.BUNDLE.getString("view");
}
@Override
public ImageIcon getIcon() {
return null;
}
@Override
public Color getTextColor() {
return Color.BLACK;
}
@Override
public Color getBackgroundColor() {
return Color.LIGHT_GRAY;
}
@Override
public void actionPerformed() {
if (target instanceof Map.Entry) {
final Instance inst = (Instance) ((Map.Entry)target).getKey();
final String type = (String) ((Map.Entry)target).getValue();
final String lowerType = type.toLowerCase();
if(!(lowerType.equals("wms") || lowerType.equals("wmts") || lowerType.equals("wfs"))){
//not a viewable type
return;
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
getDisplayer().display(serverV2, type, inst);
}
});
}
}
@Override
public Action clone() {
final Action action = new ServiceViewAction();
action.addPropertyChangeListener(this.getPropertyListeners());
return action;
}
}