Windchill: Using custom actions in profiles

 IT, Java  Kommentare deaktiviert für Windchill: Using custom actions in profiles
Jan 272015
 

Windchills profile mechanism allows the administrator to show or hide UI components such as attributes and actions. Profiles can be defined on site or organisation level. The Product or Library manager is able to override the profiles from the team page on the product / library by using the Configure Actions for Roles mechanism.

The custom actions (defined in Windchill\codebase\config\actions\customActions.xml) are not directly visible when creating or changing a profile. To make them visible (and selectable) inside the profiles, you have to add them to the config file for profiles (Windchill\codebase\roleaccessprefs.xml)

Example customActions.xml:

<listofactions>
	<objecttype name="object" class="java.lang.Object" resourceBundle="com.pbo.resource.NavigationRB">
		<action name="testPhilipp">
			<command url="netmarkets/jsp/test.jsp" windowType="popup"/>
		</action>
	</objecttype>
</listofactions>

To make the action „testPhilipp“ available in the profiles, you have to add an <uic> element in the roleaccessprefs.xml file:

<product labelId="productLabel">
	 <!-- Adding the action "testPhilipp" to the product level -->
	  <uic name="testPhilipp" order="1010" enabled="true" defaultAll="false" defaultManager="true" 
	          defaultGuest="false" managerEnabled="true" guestEnabled="false"/>

The value of the attribte name in the action-tag must be equal to the name attribute in the uic tag. It is also possible to add a uicomponent attribute when defining your custom action and use its value to reference the action in the roleaccessprefs.xml:

<listofactions>
	<objecttype name="object" class="java.lang.Object" resourceBundle="com.pbo.resource.NavigationRB">
		<action name="testPhilipp" uicomponent="myUicName">
			<command url="netmarkets/jsp/test.jsp" windowType="popup"/>
		</action>
	</objecttype>
</listofactions>

roleaccessprefs.xml:

<product labelId="productLabel">
	 <!-- Adding the action "testPhilipp" to the product level -->
	  <uic name="myUicName" order="1010" enabled="true" defaultAll="false" defaultManager="true" 
	          defaultGuest="false" managerEnabled="true" guestEnabled="false"/>

 

Now you can restart Windchill and you will see your action „testPhilipp“ when changing or creating a profile. To show a more detailed (and maybe localized) name you can use ResourceBundles. Add an entry to the roleAccessResource.rbInfo file.

Java Serialization – Example

 IT, Java  Kommentare deaktiviert für Java Serialization – Example
Mai 212013
 

First create an object that you want to store persistently (serialize). I use the object „Car“. Please ensure that your class implements the interface Serializable

package com.philipp.testing;

import java.io.Serializable;

public class Car implements Serializable {

	public enum Brand {
		BMW, Mercedes, Porsche, Audi
	};

	private Brand brand;
	private String model = "";
	private int hoursepower = 0;
	private int price = 0;

	public Car(Brand brand, String model, int hoursepower, int price) {
		super();
		this.brand = brand;
		this.model = model;
		this.hoursepower = hoursepower;
		this.price = price;
	}

	public Brand getBrand() {
		return brand;
	}

	// removed some "Getter" and "Setter" for this example..

	public void setPrice(int price) {
		this.price = price;
	}

}

Now create a „testing“ class that will create a new car and serializes it:

package com.philipp.testing;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import com.philipp.testing.Car.Brand;

public class testingTheSerialization {

	public static void main(String[] args) {

		// create a new Car
		Car myCar = new Car(Brand.Porsche, "911 Carrera S", 400, 20000);

		// now store the car in a file (serialize it):
		System.out.println("Serialize the car to file myCar.file");
		doSerialize(myCar);
		System.out.println("Serialization done");

		// now try to read the file and parse the object to a new car:
		Car myCarFromFile = null;
		myCarFromFile  =  (Car) doDeSerialize("myCar.file");
		System.out.println("Your car is: " + myCarFromFile.getBrand() +  " - " + 
								myCarFromFile.getModel() + " - " +
								myCarFromFile.getHoursepower() + "hourspower - " + 
								myCarFromFile.getPrice() + "Euro");

		System.out.println("Deserialization done...");

	}

	public static void doSerialize(Car myCar){
		FileOutputStream fos;
		try {
			fos = new FileOutputStream(new File("myCar.file"));
			ObjectOutputStream oos = new ObjectOutputStream(fos);
			oos.writeObject(myCar);
			oos.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Uuups, something went wrong: " + e.getLocalizedMessage());
		}

	}

	public static Car doDeSerialize(String filename){
		Car myCar = null;
		try {
			FileInputStream fis = new FileInputStream(new File(filename));
			ObjectInputStream ois = new ObjectInputStream(fis);
			myCar = (Car) ois.readObject();
			ois.close();
		} catch (IOException | ClassNotFoundException e) {
			e.printStackTrace();
			System.out.println("Uuups, something went wrong: " + e.getLocalizedMessage());
		}

		return myCar;
	}
}

The Output of this example is:

Serialize the car to file myCar.file
Serialization done
Your car is: Porsche - 911 Carrera S - 400hourspower - 20000Euro
Deserialization done...

And a file „myCar.file“ was created in your working directory.