com.intellij.designer.model.MetaModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ui-designer-core Show documentation
Show all versions of ui-designer-core Show documentation
A packaging of the IntelliJ Community Edition ui-designer-core library.
This is release number 1 of trunk branch 142.
The newest version!
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* 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 com.intellij.designer.model;
import com.intellij.designer.palette.DefaultPaletteItem;
import com.intellij.designer.palette.PaletteItem;
import com.intellij.designer.propertyTable.IPropertyDecorator;
import com.intellij.openapi.util.IconLoader;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.Collections;
import java.util.List;
/**
* @author Alexander Lobas
*/
public class MetaModel {
private final Class myModel;
private Class myLayout;
private final String myTarget;
private final String myTag;
private PaletteItem myPaletteItem;
private String myTitle;
private String myIconPath;
private Icon myIcon;
private String myCreation;
private boolean myDelete = true;
private List myInplaceProperties = Collections.emptyList();
private List myTopProperties = Collections.emptyList();
private List myNormalProperties = Collections.emptyList();
private List myImportantProperties = Collections.emptyList();
private List myExpertProperties = Collections.emptyList();
private List myDeprecatedProperties = Collections.emptyList();
private List myMorphingModels = Collections.emptyList();
public MetaModel(Class model, String target, String tag) {
myModel = model;
myTarget = target;
myTag = tag;
}
public Class getModel() {
return myModel;
}
public Class getLayout() {
return myLayout;
}
public void setLayout(Class layout) {
myLayout = layout;
}
public String getTarget() {
return myTarget;
}
public String getTag() {
return myTag;
}
public boolean isTag(@NotNull String tag) {
return tag.equals(myTag);
}
public boolean isTag(String... tags) {
return ArrayUtil.contains(myTag, tags);
}
public String getCreation() {
return myCreation;
}
public void setCreation(String creation) {
myCreation = creation;
}
public boolean canDelete() {
return myDelete;
}
public void setDelete(boolean delete) {
myDelete = delete;
}
public String getTitle() {
return myTitle;
}
public Icon getIcon() {
if (myIcon == null) {
if (myIconPath == null) {
return myPaletteItem == null ? null : myPaletteItem.getIcon();
}
myIcon = IconLoader.findIcon(myIconPath, myModel);
}
return myIcon;
}
public void setPresentation(String title, String iconPath) {
myTitle = title;
myIconPath = iconPath;
myIcon = null;
}
public PaletteItem getPaletteItem() {
return myPaletteItem;
}
public void setPaletteItem(@NotNull DefaultPaletteItem paletteItem) {
myPaletteItem = paletteItem;
myPaletteItem.setMetaModel(this);
}
public List getMorphingModels() {
return myMorphingModels;
}
public void setMorphingModels(List morphingModels) {
myMorphingModels = morphingModels;
}
public List getInplaceProperties() {
return myInplaceProperties;
}
public void setInplaceProperties(List inplaceProperties) {
myInplaceProperties = inplaceProperties;
}
public List getTopProperties() {
return myTopProperties;
}
public void setTopProperties(List topProperties) {
myTopProperties = topProperties;
}
public void setNormalProperties(List normalProperties) {
myNormalProperties = normalProperties;
}
public boolean isImportantProperty(String name) {
return myImportantProperties.contains(name);
}
public void setImportantProperties(List importantProperties) {
myImportantProperties = importantProperties;
}
public boolean isExpertProperty(String name) {
return myExpertProperties.contains(name);
}
public void setExpertProperties(List expertProperties) {
myExpertProperties = expertProperties;
}
public boolean isDeprecatedProperty(String name) {
return myDeprecatedProperties.contains(name);
}
public void setDeprecatedProperties(List deprecatedProperties) {
myDeprecatedProperties = deprecatedProperties;
}
public void decorate0(Property property, String name) {
property.setImportant(isImportantProperty(name));
property.setExpert(isExpertProperty(name));
property.setDeprecated(isDeprecatedProperty(name));
}
public void decorate(Property property, String name) {
decorate0(property, name);
if (property instanceof IPropertyDecorator) {
((IPropertyDecorator)property).decorate(this);
}
}
public Property decorateWithOverride(Property property) {
String name = property.getName();
if (myNormalProperties.contains(name) ||
myImportantProperties.contains(name) ||
myExpertProperties.contains(name) ||
myDeprecatedProperties.contains(name)) {
property = property.createForNewPresentation();
decorate(property, name);
}
return property;
}
}