From d1401fc172527ba931135d5583c02005dcaf2d84 Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 10 Sep 2008 00:18:35 +0000 Subject: Add a skeleton for Calculator RCP git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@693665 13f79535-47bb-0310-9956-ffa450edef68 --- .../samples/calculator-rcp/META-INF/MANIFEST.MF | 25 ++++ java/sca/samples/calculator-rcp/build.properties | 5 + .../samples/calculator-rcp/icons/alt_window_16.gif | Bin 0 -> 637 bytes .../samples/calculator-rcp/icons/alt_window_32.gif | Bin 0 -> 1192 bytes java/sca/samples/calculator-rcp/plugin.xml | 31 +++++ java/sca/samples/calculator-rcp/pom.xml | 126 +++++++++++++++++++++ .../src/main/java/Calculator.composite | 54 +++++++++ .../src/main/java/calculator/AddService.java | 28 +++++ .../src/main/java/calculator/AddServiceImpl.java | 35 ++++++ .../src/main/java/calculator/CalculatorClient.java | 52 +++++++++ .../main/java/calculator/CalculatorService.java | 34 ++++++ .../java/calculator/CalculatorServiceImpl.java | 69 +++++++++++ .../src/main/java/calculator/DivideService.java | 28 +++++ .../main/java/calculator/DivideServiceImpl.java | 35 ++++++ .../src/main/java/calculator/MultiplyService.java | 28 +++++ .../main/java/calculator/MultiplyServiceImpl.java | 35 ++++++ .../src/main/java/calculator/SubtractService.java | 28 +++++ .../main/java/calculator/SubtractServiceImpl.java | 35 ++++++ .../src/main/java/calculator/rcp/Activator.java | 79 +++++++++++++ .../src/main/java/calculator/rcp/Application.java | 63 +++++++++++ .../rcp/ApplicationActionBarAdvisor.java | 65 +++++++++++ .../rcp/ApplicationWorkbenchAdvisor.java | 37 ++++++ .../rcp/ApplicationWorkbenchWindowAdvisor.java | 44 +++++++ .../src/main/java/calculator/rcp/Perspective.java | 34 ++++++ .../src/main/java/calculator/rcp/View.java | 88 ++++++++++++++ 25 files changed, 1058 insertions(+) create mode 100644 java/sca/samples/calculator-rcp/META-INF/MANIFEST.MF create mode 100644 java/sca/samples/calculator-rcp/build.properties create mode 100644 java/sca/samples/calculator-rcp/icons/alt_window_16.gif create mode 100644 java/sca/samples/calculator-rcp/icons/alt_window_32.gif create mode 100644 java/sca/samples/calculator-rcp/plugin.xml create mode 100644 java/sca/samples/calculator-rcp/pom.xml create mode 100644 java/sca/samples/calculator-rcp/src/main/java/Calculator.composite create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/AddService.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/AddServiceImpl.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/CalculatorClient.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/CalculatorService.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/DivideService.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/DivideServiceImpl.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/MultiplyService.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/SubtractService.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/Application.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/ApplicationActionBarAdvisor.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/ApplicationWorkbenchAdvisor.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/ApplicationWorkbenchWindowAdvisor.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/Perspective.java create mode 100644 java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/View.java (limited to 'java/sca') diff --git a/java/sca/samples/calculator-rcp/META-INF/MANIFEST.MF b/java/sca/samples/calculator-rcp/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..57ecdff710 --- /dev/null +++ b/java/sca/samples/calculator-rcp/META-INF/MANIFEST.MF @@ -0,0 +1,25 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Apache Tuscany SCA Calculator RCP Sample +Bundle-SymbolicName: sample.calculator.rcp;singleton:=true +Bundle-Version: 1.4.0.SNAPSHOT +Bundle-Activator: calculator.rcp.Activator +Bundle-Vendor: The Apache Software Foundation +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-ActivationPolicy: lazy +Import-Package: org.osoa.sca;version="1.4.0", + org.osoa.sca.annotations;version="1.4.0" +Bundle-ClassPath: ., + cglib-nodep-2.1_3.jar, + jaxb-impl-2.1.7.jar, + activation-1.1.jar, + jsr250-api-1.0.jar, + jsr181-api-1.0-MR1.jar, + jaxb-api-2.1.jar, + stax-api-1.0-2.jar, + jaxws-api-2.1.jar, + geronimo-commonj_1.1_spec-1.0.jar, + XmlSchema-1.3.2.jar, + wstx-asl-3.2.1.jar diff --git a/java/sca/samples/calculator-rcp/build.properties b/java/sca/samples/calculator-rcp/build.properties new file mode 100644 index 0000000000..0530eb648b --- /dev/null +++ b/java/sca/samples/calculator-rcp/build.properties @@ -0,0 +1,5 @@ +source.. = src/main/java/ +output.. = target/classes/ +bin.includes = plugin.xml,\ + META-INF/,\ + . diff --git a/java/sca/samples/calculator-rcp/icons/alt_window_16.gif b/java/sca/samples/calculator-rcp/icons/alt_window_16.gif new file mode 100644 index 0000000000..05626b17d8 Binary files /dev/null and b/java/sca/samples/calculator-rcp/icons/alt_window_16.gif differ diff --git a/java/sca/samples/calculator-rcp/icons/alt_window_32.gif b/java/sca/samples/calculator-rcp/icons/alt_window_32.gif new file mode 100644 index 0000000000..b432f88339 Binary files /dev/null and b/java/sca/samples/calculator-rcp/icons/alt_window_32.gif differ diff --git a/java/sca/samples/calculator-rcp/plugin.xml b/java/sca/samples/calculator-rcp/plugin.xml new file mode 100644 index 0000000000..1fb5acd9b5 --- /dev/null +++ b/java/sca/samples/calculator-rcp/plugin.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/java/sca/samples/calculator-rcp/pom.xml b/java/sca/samples/calculator-rcp/pom.xml new file mode 100644 index 0000000000..a487076de6 --- /dev/null +++ b/java/sca/samples/calculator-rcp/pom.xml @@ -0,0 +1,126 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.4-SNAPSHOT + ../../pom.xml + + sample.calculator.rcp + Apache Tuscany SCA Calculator RCP Sample + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-node-api + 1.4-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-node-impl + 1.4-SNAPSHOT + runtime + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.4-SNAPSHOT + runtime + + + org.apache.tuscany.sca + tuscany-implementation-node-runtime + 1.4-SNAPSHOT + runtime + + + org.apache.tuscany.sca + tuscany-extensibility-equinox + 1.4-SNAPSHOT + runtime + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + 1.4-SNAPSHOT + compile + + + + javax.servlet + servlet-api + 2.5 + provided + + + junit + junit + 4.2 + test + + + + ${artifactId} + + + maven-eclipse-plugin + 2.5.1 + + + org.eclipse.pde.ManifestBuilder + org.eclipse.jdt.core.javabuilder + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + + org.eclipse.jdt.launching.JRE_CONTAINER + + org.eclipse.pde.core.requiredPlugins + + + + + + maven-jar-plugin + + + ${basedir}/META-INF/MANIFEST.MF + + + + + + \ No newline at end of file diff --git a/java/sca/samples/calculator-rcp/src/main/java/Calculator.composite b/java/sca/samples/calculator-rcp/src/main/java/Calculator.composite new file mode 100644 index 0000000000..913081b9be --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/Calculator.composite @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/AddService.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..188451ebac --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/AddService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator; + +/** + * The Add service interface + */ +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/AddServiceImpl.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..7ca8fb04b5 --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/AddServiceImpl.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Add service + */ +public class AddServiceImpl implements AddService { + + public double add(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Adding " + n1 + " and " + n2); + return n1 + n2; + } + +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/CalculatorClient.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..adbd18a9e4 --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/CalculatorClient.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator; + +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + */ +@Scope("COMPOSITE") +@EagerInit +public class CalculatorClient { + + private CalculatorService calculatorService; + + @Reference + public void setCalculatorService(CalculatorService calculatorService) { + this.calculatorService = calculatorService; + } + + @Init + public void calculate() { + // Calculate + System.out.println("SCA API ClassLoader: " + Reference.class.getClassLoader()); + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + } + +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/CalculatorService.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..c89043276e --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator; + +/** + * The Calculator service interface. + */ +public interface CalculatorService { + + double add(double n1, double n2); + + double subtract(double n1, double n2); + + double multiply(double n1, double n2); + + double divide(double n1, double n2); + +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/CalculatorServiceImpl.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..ba897fa301 --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator; + +import org.osoa.sca.annotations.Reference; + +/** + * An implementation of the Calculator service. + */ +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } + +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/DivideService.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..30d248208b --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator; + +/** + * The divide service interface + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/DivideServiceImpl.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..1323edf55a --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/DivideServiceImpl.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Divide service. + */ +public class DivideServiceImpl implements DivideService { + + public double divide(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Dividing " + n1 + " with " + n2); + return n1 / n2; + } + +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/MultiplyService.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/MultiplyServiceImpl.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..91b803bc9e --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/MultiplyServiceImpl.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Multiply service. + */ +public class MultiplyServiceImpl implements MultiplyService { + + public double multiply(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Multiplying " + n1 + " with " + n2); + return n1 * n2; + } + +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/SubtractService.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..bf0d1882b6 --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator; + +/** + * The interface for the multiply service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/SubtractServiceImpl.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..58cc4a3547 --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/SubtractServiceImpl.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the subtract service. + */ +public class SubtractServiceImpl implements SubtractService { + + public double subtract(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Subtracting " + n1 + " from " + n2); + return n1 - n2; + } + +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java new file mode 100644 index 0000000000..1dcf5b4e88 --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator.rcp; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.apache.tuscany.sca.sample.calculator.rcp"; + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/Application.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/Application.java new file mode 100644 index 0000000000..5ce6522fed --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/Application.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator.rcp; + +import org.eclipse.equinox.app.IApplication; +import org.eclipse.equinox.app.IApplicationContext; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.PlatformUI; + +/** + * This class controls all aspects of the application's execution + */ +public class Application implements IApplication { + + /* (non-Javadoc) + * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext) + */ + public Object start(IApplicationContext context) { + Display display = PlatformUI.createDisplay(); + try { + int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); + if (returnCode == PlatformUI.RETURN_RESTART) { + return IApplication.EXIT_RESTART; + } + return IApplication.EXIT_OK; + } finally { + display.dispose(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.app.IApplication#stop() + */ + public void stop() { + final IWorkbench workbench = PlatformUI.getWorkbench(); + if (workbench == null) + return; + final Display display = workbench.getDisplay(); + display.syncExec(new Runnable() { + public void run() { + if (!display.isDisposed()) + workbench.close(); + } + }); + } +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/ApplicationActionBarAdvisor.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/ApplicationActionBarAdvisor.java new file mode 100644 index 0000000000..2fccfb2d77 --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/ApplicationActionBarAdvisor.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator.rcp; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; +import org.eclipse.ui.application.ActionBarAdvisor; +import org.eclipse.ui.application.IActionBarConfigurer; + +/** + * An action bar advisor is responsible for creating, adding, and disposing of + * the actions added to a workbench window. Each window will be populated with + * new actions. + */ +public class ApplicationActionBarAdvisor extends ActionBarAdvisor { + + // Actions - important to allocate these only in makeActions, and then use + // them + // in the fill methods. This ensures that the actions aren't recreated + // when fillActionBars is called with FILL_PROXY. + private IWorkbenchAction exitAction; + + public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { + super(configurer); + } + + protected void makeActions(final IWorkbenchWindow window) { + // Creates the actions and registers them. + // Registering is needed to ensure that key bindings work. + // The corresponding commands keybindings are defined in the plugin.xml + // file. + // Registering also provides automatic disposal of the actions when + // the window is closed. + + exitAction = ActionFactory.QUIT.create(window); + register(exitAction); + } + + protected void fillMenuBar(IMenuManager menuBar) { + MenuManager fileMenu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE); + menuBar.add(fileMenu); + fileMenu.add(exitAction); + } + +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/ApplicationWorkbenchAdvisor.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/ApplicationWorkbenchAdvisor.java new file mode 100644 index 0000000000..ac1893509c --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/ApplicationWorkbenchAdvisor.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator.rcp; + +import org.eclipse.ui.application.IWorkbenchWindowConfigurer; +import org.eclipse.ui.application.WorkbenchAdvisor; +import org.eclipse.ui.application.WorkbenchWindowAdvisor; + +public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor { + + private static final String PERSPECTIVE_ID = "org.apache.tuscany.sca.sample.calculator.rcp.perspective"; + + public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { + return new ApplicationWorkbenchWindowAdvisor(configurer); + } + + public String getInitialWindowPerspectiveId() { + return PERSPECTIVE_ID; + } + +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/ApplicationWorkbenchWindowAdvisor.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/ApplicationWorkbenchWindowAdvisor.java new file mode 100644 index 0000000000..6378decf20 --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/ApplicationWorkbenchWindowAdvisor.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator.rcp; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.ui.application.ActionBarAdvisor; +import org.eclipse.ui.application.IActionBarConfigurer; +import org.eclipse.ui.application.IWorkbenchWindowConfigurer; +import org.eclipse.ui.application.WorkbenchWindowAdvisor; + +public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { + + public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { + super(configurer); + } + + public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) { + return new ApplicationActionBarAdvisor(configurer); + } + + public void preWindowOpen() { + IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); + configurer.setInitialSize(new Point(400, 300)); + configurer.setShowCoolBar(false); + configurer.setShowStatusLine(false); + configurer.setTitle("Tuscany SCA Calculator RCP Application"); + } +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/Perspective.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/Perspective.java new file mode 100644 index 0000000000..445b4b65b2 --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/Perspective.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator.rcp; + +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IPerspectiveFactory; + +public class Perspective implements IPerspectiveFactory { + + public void createInitialLayout(IPageLayout layout) { + String editorArea = layout.getEditorArea(); + layout.setEditorAreaVisible(false); + layout.setFixed(true); + + layout.addStandaloneView(View.ID, false, IPageLayout.LEFT, 1.0f, editorArea); + } + +} diff --git a/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/View.java b/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/View.java new file mode 100644 index 0000000000..f95c1e029c --- /dev/null +++ b/java/sca/samples/calculator-rcp/src/main/java/calculator/rcp/View.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 calculator.rcp; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.ViewPart; + +public class View extends ViewPart { + public static final String ID = "org.apache.tuscany.sca.sample.calculator.rcp.view"; + + private TableViewer viewer; + + /** + * The content provider class is responsible for providing objects to the + * view. It can wrap existing objects in adapters or simply return objects + * as-is. These objects may be sensitive to the current input of the view, + * or ignore it and always show the same content (like Task List, for + * example). + */ + class ViewContentProvider implements IStructuredContentProvider { + public void inputChanged(Viewer v, Object oldInput, Object newInput) { + } + + public void dispose() { + } + + public Object[] getElements(Object parent) { + return new String[] {"One", "Two", "Three"}; + } + } + + class ViewLabelProvider extends LabelProvider implements ITableLabelProvider { + public String getColumnText(Object obj, int index) { + return getText(obj); + } + + public Image getColumnImage(Object obj, int index) { + return getImage(obj); + } + + public Image getImage(Object obj) { + return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); + } + } + + /** + * This is a callback that will allow us to create the viewer and initialize + * it. + */ + public void createPartControl(Composite parent) { + viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + viewer.setContentProvider(new ViewContentProvider()); + viewer.setLabelProvider(new ViewLabelProvider()); + viewer.setInput(getViewSite()); + } + + /** + * Passing the focus request to the viewer's control. + */ + public void setFocus() { + viewer.getControl().setFocus(); + } +} -- cgit v1.2.3