All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.activiti.designer.eclipse.common.SampleUtil Maven / Gradle / Ivy

The newest version!
/**
 * 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.activiti.designer.eclipse.common;

import org.eclipse.graphiti.mm.algorithms.styles.Color;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.ColorDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;

public class SampleUtil {

	/**
	 * Opens an simple input dialog with OK and Cancel buttons.
	 * 

* * @param dialogTitle * the dialog title, or null if none * @param dialogMessage * the dialog message, or null if none * @param initialValue * the initial input value, or null if none * (equivalent to the empty string) * @return the string */ public static String askString(String dialogTitle, String dialogMessage, String initialValue) { String ret = null; Shell shell = getShell(); InputDialog inputDialog = new InputDialog(shell, dialogTitle, dialogMessage, initialValue, null); int retDialog = inputDialog.open(); if (retDialog == Window.OK) { ret = inputDialog.getValue(); } return ret; } /** * Opens a dialog to change the color. * * @param color * the color to change * @return the changed color */ public static Color editColor(Color color) { if (color != null && color.eContainer() instanceof Diagram) { Shell shell = getShell(); ColorDialog colorDialog = new ColorDialog(shell); colorDialog.setText("Choose Color"); colorDialog.setRGB(new RGB(color.getRed(), color.getGreen(), color.getBlue())); RGB retRgb = colorDialog.open(); if (retRgb == null) { return null; } Diagram diagram = (Diagram) color.eContainer(); Color newColor = Graphiti.getGaService().manageColor(diagram, retRgb.red, retRgb.green, retRgb.blue); return newColor; } return null; } /** * Returns the currently active Shell. * * @return The currently active Shell. */ private static Shell getShell() { return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy