blob: 1ca5b414a80250e55698ad55a4893e124e256171 [file] [log] [blame]
/**
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*
* This copyright notice shows up in the generated Java code
*/
package org.eclipse.osbp.xtext.reportdsl.ui.contentassist;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.osbp.xtext.reportdsl.Color;
import org.eclipse.osbp.xtext.reportdsl.common.ColorUtilities;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.ColorDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ui.editor.contentassist.ReplacementTextApplier;
@SuppressWarnings("all")
public class ColorTextApplier extends ReplacementTextApplier {
private ContentAssistContext context;
public ContentAssistContext setContext(final ContentAssistContext context) {
return this.context = context;
}
@Override
public String getActualReplacementString(final ConfigurableCompletionProposal proposal) {
Display display = this.context.getViewer().getTextWidget().getDisplay();
Shell shell = new Shell(display);
FillLayout _fillLayout = new FillLayout();
shell.setLayout(_fillLayout);
ColorDialog colorDialog = new ColorDialog(shell);
EObject _currentModel = this.context.getCurrentModel();
String _color = ((Color) _currentModel).getColor();
if ((_color instanceof String)) {
try {
EObject _currentModel_1 = this.context.getCurrentModel();
java.awt.Color awtColor = ColorUtilities.convertToAwtColor(((Color) _currentModel_1));
int _red = awtColor.getRed();
int _green = awtColor.getGreen();
int _blue = awtColor.getBlue();
RGB _rGB = new RGB(_red, _green, _blue);
colorDialog.setRGB(_rGB);
} finally {
}
}
RGB newColor = colorDialog.open();
if ((newColor != null)) {
return String.format("\"#%02x%02x%02x\"", Integer.valueOf(newColor.red), Integer.valueOf(newColor.green), Integer.valueOf(newColor.blue));
}
return null;
}
}