001package gwt.material.design.addins.client.richeditor.base;
002
003/*
004 * #%L
005 * GwtMaterial
006 * %%
007 * Copyright (C) 2015 - 2016 GwtMaterialDesign
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023
024import com.google.gwt.core.client.JsArrayString;
025import com.google.gwt.dom.client.Document;
026import gwt.material.design.addins.client.richeditor.base.constants.ToolbarButton;
027import gwt.material.design.client.base.HasPlaceholder;
028import gwt.material.design.client.base.MaterialWidget;
029
030/**
031 * Base widget for Rich Editor with specific properties for options
032 */
033public class MaterialRichEditorBase extends MaterialWidget implements HasPlaceholder {
034
035    private boolean airMode;
036    private String placeholder = "";
037    private boolean disableDragAndDrop;
038
039
040    public MaterialRichEditorBase() {
041        super(Document.get().createDivElement(), "editor");
042    }
043
044    private ToolbarButton[] styleOptions = new ToolbarButton[]
045            { ToolbarButton.STYLE, ToolbarButton.BOLD, ToolbarButton.ITALIC, ToolbarButton.UNDERLINE, ToolbarButton.STRIKETHROUGH, ToolbarButton.CLEAR, ToolbarButton.SUPERSCRIPT, ToolbarButton.SUBSCRIPT };
046    private ToolbarButton[] fontOptions = new ToolbarButton[]
047            { ToolbarButton.FONT_SIZE, ToolbarButton.FONT_NAME };
048    private ToolbarButton[] colorOptions = new ToolbarButton[]
049            { ToolbarButton.COLOR };
050    private ToolbarButton[] undoOptions = new ToolbarButton[]
051            { ToolbarButton.UNDO, ToolbarButton.REDO, ToolbarButton.HELP };
052    private ToolbarButton[] ckMediaOptions = new ToolbarButton[]
053            { ToolbarButton.CK_IMAGE_UPLOAD, ToolbarButton.CK_IMAGE_VIDEO };
054    private ToolbarButton[] miscOptions = new ToolbarButton[]
055            { ToolbarButton.LINK, ToolbarButton.PICTURE, ToolbarButton.TABLE, ToolbarButton.HR, ToolbarButton.CODE_VIEW, ToolbarButton.FULLSCREEN };
056    private ToolbarButton[] paraOptions = new ToolbarButton[]
057            { ToolbarButton.UL, ToolbarButton.OL, ToolbarButton.PARAGRAPH, ToolbarButton.LEFT, ToolbarButton.CENTER, ToolbarButton.RIGHT, ToolbarButton.JUSTIFY, ToolbarButton.OUTDENT, ToolbarButton.INDENT };
058    private ToolbarButton[] heightOptions = new ToolbarButton[]
059            { ToolbarButton.LINE_HEIGHT };
060
061    public JsArrayString extractOptions(ToolbarButton[] options){
062        JsArrayString jsOptions = JsArrayString.createArray().cast();
063        for(ToolbarButton option : options){
064            jsOptions.push(option.getId());
065        }
066        return  jsOptions;
067    }
068
069    public ToolbarButton[] getStyleOptions() {
070        return styleOptions;
071    }
072
073    public void setStyleOptions(ToolbarButton... styleOptions) {
074        this.styleOptions = styleOptions;
075    }
076
077    public ToolbarButton[] getFontOptions() {
078        return fontOptions;
079    }
080
081    public void setFontOptions(ToolbarButton... fontOptions) {
082        this.fontOptions = fontOptions;
083    }
084
085    public ToolbarButton[] getColorOptions() {
086        return colorOptions;
087    }
088
089    public void setColorOptions(ToolbarButton... colorOptions) {
090        this.colorOptions = colorOptions;
091    }
092
093    public ToolbarButton[] getUndoOptions() {
094        return undoOptions;
095    }
096
097    public void setUndoOptions(ToolbarButton... undoOptions) {
098        this.undoOptions = undoOptions;
099    }
100
101    public ToolbarButton[] getCkMediaOptions() {
102        return ckMediaOptions;
103    }
104
105    public void setCkMediaOptions(ToolbarButton... ckMediaOptions) {
106        this.ckMediaOptions = ckMediaOptions;
107    }
108
109    public ToolbarButton[] getMiscOptions() {
110        return miscOptions;
111    }
112
113    public void setMiscOptions(ToolbarButton... miscOptions) {
114        this.miscOptions = miscOptions;
115    }
116
117    public ToolbarButton[] getParaOptions() {
118        return paraOptions;
119    }
120
121    public void setParaOptions(ToolbarButton... paraOptions) {
122        this.paraOptions = paraOptions;
123    }
124
125    public ToolbarButton[] getHeightOptions() {
126        return heightOptions;
127    }
128
129    public void setHeightOptions(ToolbarButton... heightOptions) {
130        this.heightOptions = heightOptions;
131    }
132
133    public boolean isAirMode() {
134        return airMode;
135    }
136
137    public void setAirMode(boolean airMode) {
138        this.airMode = airMode;
139    }
140
141    @Override
142    public String getPlaceholder() {
143        return placeholder;
144    }
145
146    @Override
147    public void setPlaceholder(String placeholder) {
148        this.placeholder = placeholder;
149    }
150
151    public String getHeight() {
152        String height = getElement().getStyle().getHeight();
153        if(height == null || height.isEmpty()){
154            height = "550px";
155        }
156        return height;
157    }
158
159    /**
160     * Check if the dnd for rich editor is enabled / disabled
161     */
162    public boolean isDisableDragAndDrop() {
163        return disableDragAndDrop;
164    }
165
166    /**
167     * If true, disable the ability to drag and drop items to rich editor
168     */
169    public void setDisableDragAndDrop(boolean disableDragAndDrop) {
170        this.disableDragAndDrop = disableDragAndDrop;
171    }
172}